[command-line] How do you input command line arguments in IntelliJ IDEA?

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.

This question is related to command-line arguments intellij-idea

The answer is


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


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


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.


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


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

Program arguments:Julia 52 Actress


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.


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.


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

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.


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.


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


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.


maytham-???i???, 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]));

Examples related to command-line

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Flutter command not found Angular - ng: command not found how to run python files in windows command prompt? How to run .NET Core console app from the command line Copy Paste in Bash on Ubuntu on Windows How to find which version of TensorFlow is installed in my system? How to install JQ on Mac by command-line? Python not working in the command line of git bash Run function in script from command line (Node JS)

Examples related to arguments

docker build with --build-arg with multiple arguments ARG or ENV, which one to use in this case? How to have multiple conditions for one if statement in python Gradle task - pass arguments to Java application Angularjs - Pass argument to directive TypeError: method() takes 1 positional argument but 2 were given Best way to check function arguments? "Actual or formal argument lists differs in length" Python: Passing variables between functions Print multiple arguments in Python

Examples related to intellij-idea

IntelliJ: Error:java: error: release version 5 not supported Has been compiled by a more recent version of the Java Runtime (class file version 57.0) Error: Java: invalid target release: 11 - IntelliJ IDEA IntelliJ can't recognize JavaFX 11 with OpenJDK 11 Error: JavaFX runtime components are missing, and are required to run this application with JDK 11 ERROR Source option 1.5 is no longer supported. Use 1.6 or later Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6 How to configure "Shorten command line" method for whole project in IntelliJ intellij idea - Error: java: invalid source release 1.9 Failed to resolve: com.google.android.gms:play-services in IntelliJ Idea with gradle