7

I am new in intellij. I would like to add program arguments for my maven command line application so that they can be used in main(String[] args) method, such as: -pg 541, which specified some method to be triggered in my main function.

I was tried to do it using Maven configuration (Run/Debug Configurations) by adding arguments directly in Command line section but it didn't succeed.

I tried also JUnit which runs Maven project but the program arguments section was disabled.

Here is a snapshot of what I tried.

using junit configuration:

using junit configuration

using maven configuration:

using maven configuration

Gangaraju
  • 4,406
  • 9
  • 45
  • 77
kal
  • 73
  • 1
  • 5
  • Possible duplicate of [IntelliJ - Convert a Java project/module into a Maven project/module](http://stackoverflow.com/questions/7642456/intellij-convert-a-java-project-module-into-a-maven-project-module) – KishanCS Feb 16 '17 at 12:56
  • The project is already maven! I do not need to convert a project into maven. I need a possible way to pass program argument to main function. – kal Feb 16 '17 at 13:03

1 Answers1

14

JUnit tests are executed via the test runner framework, your main method is not called at all by JUnit, therefore you can't supply program arguments this way.

To pass the arguments to the application via its main method you have to use Application Run/Debug configuration type in IDEA.

If you want to pass parameters to the unit tests, consider using VM Options field instead, like -Dparam=value and in the test method you can read it with String value = System.getProperty("param");

Maven supports it as well using argLine in some unit test plugins.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904