243

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.

3
  • 2
    I've used like 20+ IDEs in my life and this is the 1st one for which I had to search the web how the heck to do such a trivial thing. For every other one it was intuitive. And to add injurity to the insult, if the (gradle or whatever) project throws an exception when it runs, this IDE doesn't show it, never mind break to right line in the source! Just gives the equivalent of "something went wrong". Worse than using the command line directly, at least out of the box. Commented Jul 5, 2024 at 18:10
  • And the latter Q is... answerless stackoverflow.com/questions/41144023/… Commented Jul 5, 2024 at 18:25
  • I see that the company saying they'll remove the old UI at some point (where stuff is less hidden by default) wasn't exactly popular intellij-support.jetbrains.com/hc/en-us/community/posts/… (-37 score on that, LOL). Commented Jul 6, 2024 at 8:19

18 Answers 18

263

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Same thing but start with CTRL+ALT+D for debug configuration on OS X 10.5+ schema.
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?
@RossoTheMan I mean the key on the keyboard that's usually located between W and R.
LOL. Makes emacs key cobos look easy to remember, in comparison.
Pancrit answer is better. I hate shortcut keys, everyone could be different with a custom key map. Also reminds me of green screen tab key entry...ugh.
102

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.

5 Comments

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.
@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?
@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.
Note that the main menu is hidden by default in the 2024 version of IDEA. 'Edit configuration' is actually accessible from two places now, but alas both are hidden in some fashion: the main menu (which you can access on left via the quad-hamburger or Alt+\) and the top toolbar on the right with the run & debug [green] icons. In the latter [toolbar] 'edit configuration' is hidden under the dropdown mini-menu with three vertical dots.
Ed's answer below cover how this looks in the 2024 version.
76

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.

Comments

44

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.

1 Comment

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.
38

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 :)

Comments

9

You separate multiple program arguments with spaces. (this was not obvious to me)

Program arguments:Julia 52 Actress

Comments

7

Just left click on your current configuration (mine is Main) and select Edit Configurations, enter image description here

then in the input field Program arguments enter your values as you would in the console, click OK.

enter image description here

2 Comments

if the "Program arguments" is not shown like in the picture, click on the "Modify options" and select "Program arguments"
This is more or less how it looks in the 2024 version too. There are two ways to get to that dialog actually. The mini-menu you've shown which is now (2024) shown as three vertical dots or the Run menu in the main menu accessible via the four-line hamburger. (I guess they like double whoppers at IntelliJ, LOL.) Actually there are 3 ways. There's also the right-click menu as shown in user 452866's answer below that I hadn't noticed.
4

On a MacBook Air with "OSX 10.11.3":

  1. ctrl + alt + r
  2. e
  3. Enter
  4. Program arguments: Write your command line parameters (space between each item if you have more than one argument)
  5. Enter

1 Comment

Duplicate of an existing ealier answer.
4

Do this steps :-

Go to Run - Edit Configuration -> Application (on the left of the panel ) -> select the scala application that u want to run -> program argument

Comments

4

I am using IDEA 2021.3.2 exactly, and I run across a simple solution: Just right click in your code area:

step1

Then choose Modify Run Configuration:

step 2

Input your command line parameters there.

2 Comments

Not the most obvious place to look for this, but good that it's there also... I guess. (Although it does clutter the right-click menu with stuff that's less... contextual.)
this worked for me. Super non-obvious. In contrast, the Run menu with "Edit configuration" did not work, since I had to add a new configuration, and it had a blank Main class which I could not change.
3
  1. Click on the 'Edit configurations...' from the top of the toolbar enter image description here

  2. In the popup-window, ensure that the 'Environment' section is expanded out (by clicking on the dropdown arrow) enter image description here

  3. Application's Command line arguments should go into the 'Program arguments' field enter image description here

Comments

2

maytham-ɯɐɥıλɐɯ, you can use this code to simulate input of file:

System.setIn(new FileInputStream("FILE_NAME"));

Or send file name as parameter and then put it into FileInputStream:

System.setIn(new FileInputStream(args[0]));

Comments

2

Main Program -> Run -> Edit Configurations -> Inside Configuration there is Program arguments text box. add space separated argument in the text box. Then you can read those arguments in the args array (public static void main(String[] args))

Comments

2

As @EastOcean said, We can add it by choosing Run/Debug configurations option. In my case, I have to set configuration for junit. So on clicking Edit configurations option, a pop up window is displayed. Then followed the below steps:

  1. Click on + icon
  2. Choose junit from the list
  3. Then we can see Configuration tab in the right hand side
  4. Select test kind, in my case Its a Class
  5. Next step browse through the location of the class which needs to be executed/run
  6. Next to that, choose VM Option, click on expand arrow icons
  7. Set required arguments for an example (-Durl="http://test.com/home" -Dsourcename="API" -Dbrowsername="chrome")
  8. Set jre path.

Save and run.

Thank you.

Comments

1

In IntelliJ, if you want to pass args parameters to the main method.

go to-> edit configurations

program arguments: 5 10 25

you need to pass the arguments through space separated and click apply and save.

now run the program if you print

System.out.println(args[0]); System.out.println(args[1]); System.out.println(args[2]); Out put is 5 10 25

Comments

1

I'm adding an updated answer to this question since IntelliJ IDEA 2021.

  1. Select Edit Configuration from the toolbar (or under the Run menu): Picture of new location of edit configuration box

  2. You now have to click on the Modify Options menu (Alt + M) to the left of where it says Build and Run, and above the drop down menu that lets you select the version of Java (or other language) that your using.

  3. After you click Modify Options the first box you will see--titled Operating System--will have a line that says "Redirect input". Click on that to add the box for input redirection. Close Modify Options.

  4. Under Build and Run, the third box down is for command line input.

Picture of Intelij IDE with Edit Configuration box open with arrows pointing to cmd line input and input redirection

That's all there is to it.

Comments

0

It's strange that no one wrote about simply copying "Run" command output into your terminal and adding the arguments.

For example, when I run "Run" command in my Intellij IDEA the output is something like

/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -javaagent:/opt/idea-IC-211.7142.45/lib/idea_rt.jar=32887:/opt/idea-IC-211.7142.45/bin -Dfile.encoding=UTF-8 -classpath /home/aliaksei/Projects/Training/Java/firstTry/out/production/firstTry MyClass

Process finished with exit code 0

And then I simply copy the first line and enter my arguments like:

<THIS_HUGE_LINE> foo bar

Note: remember to build the project before running the command in terminal. Either click "Build" or "Run" first. You can find these options, for example, at the bottom: link to the screenshot

Comments

-1

To do this in IntelliJ IDEA 2020.2.3 (Community edition) on Windows 10:

  1. ALT-SHIFT-F10
  2. 0
  3. [TAB] 7 times

Updated for 11/2020.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.