How do you input command line arguments in IntelliJ IDEA?

340,478

Solution 1

Windows, Linux, some Macs:

ALT+SHIFT+F10, Right, E, Enter, Tab, enter your command line parameters, Enter. ;-)

Mac with "OS X 10.5" key schema:

CTRL+ALT+R, Right, E, Enter, Tab, enter your command line parameters, Enter.

Solution 2

There's an "edit configurations" item on the Run menu, and on the pull-down to the left of the two green "run" and "debug" arrows on the toolbar. In that panel, you create a configuration with the "+" button in the top left, and then you can choose the Class containing main(), add VM parameters and command-line args, specify the working directory and any environment variables.

There are other options there as well: code coverage, logging, build, JRE, etc.

Solution 3

If you are using intellij go to Run > Edit Configurations menu setting. A dialog box will appear. Now you can add arguments to the Program arguments input field.

Solution 4

Example I have a class Test:

Class Test

Then. Go to config to run class Test:

Step 1: Add Application

Add Application

Step 2:

Edit Configurations...

You can input arguments in the Program Arguments textbox.

Solution 5

We cannot go into Terminal and give in the good old java Classname arg1 arg2 arg3

We'll have to edit the run configuration.

Step 1 : Take the Run menu
Step 2 : Select Edit Configurations
Step 3 : Fill the Program arguments field

enter image description here

After that, the arguments will be inserted to the end of the command that IntelliJ creates whenever you run the program :)

Share:
340,478

Related videos on Youtube

sungkwangsong
Author by

sungkwangsong

Updated on March 31, 2022

Comments

  • sungkwangsong
    sungkwangsong over 2 years

    I usually input command line arguments in Eclipse via run configuration. But I don't know how do achieve the same task in IntelliJ IDEA.

  • SMPH
    SMPH about 10 years
    This is how I run in commandline $gradle cucumber -Ptags=@Cal -Penv=dev1. I entered vales under Edit Config.. > Program Arguments as --tags "@Cal" "env=dev1". I noticed @Cal worked and env=dev1 doesn't work.
  • Maytham Fahmi
    Maytham Fahmi almost 9 years
    @PanCrit In my console when I do java MyClass < someFileName.txt it works, but when I add < someFileName.txt to program arguments in intelliJ, it does return Error: Could not find or load main class < Any idea how to solve it?
  • michaelsnowden
    michaelsnowden almost 8 years
    Same thing but start with CTRL+ALT+D for debug configuration on OS X 10.5+ schema.
  • Kyung Lee
    Kyung Lee almost 8 years
    What if I wanna use a redirect symbol? For example, $ javac Filter WhiteList.txt < TotalList.txt, how can I run this in Intellij just like command lines?
  • Isinlor
    Isinlor over 5 years
    TIL that we can use variables in program arguments of run configuration: youtrack.jetbrains.com/issue/IDEA-74031 It is possible for example to use the current file path as an argument or just make a prompt.
  • Kalle Richter
    Kalle Richter over 5 years
    Duplicate of an existing ealier answer.
  • Nowaker
    Nowaker over 3 years
    @RossoTheMan I mean the key on the keyboard that's usually located between W and R.
  • PanCrit
    PanCrit almost 3 years
    @maytham-ɯɐɥʇʎɐɯ, I wouldn't expect "< filename" to work in intelliJ, since that's explicitly shell syntax for a redirect to stdIn. IntelliJ would only be expecting to handle arguments that the program itself knows how to interpret. Is there any chance the program takes the name of input files as a parameter? That would be supported.