[英]how to add program arguments for maven command line project in intellij?
I am new in intellij. 我是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. 我想为我的maven命令行应用程序添加程序参数,以便它们可以在
main(String[] args)
方法中使用,例如: -pg 541
,它指定了一些在我的main函数中触发的方法。
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. 我试图通过直接在命令行部分添加参数使用Maven配置(运行/调试配置)来完成它,但它没有成功。
I tried also JUnit which runs Maven project but the program arguments section was disabled. 我还尝试了运行Maven项目的JUnit,但是程序参数部分被禁用了。
Here is a snapshot of what I tried. 这是我尝试过的快照。
using junit configuration: 使用junit配置:
using maven configuration: 使用maven配置:
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. JUnit测试是通过测试运行器框架执行的,JUnit根本不调用你的
main
方法,因此你不能以这种方式提供程序参数。
To pass the arguments to the application via its main
method you have to use Application Run/Debug configuration type in IDEA. 要通过其
main
方法将参数传递给应用程序,您必须在IDEA中使用Application Run / Debug配置类型。
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");
如果要将参数传递给单元测试,请考虑使用VM Options字段,例如
-Dparam=value
,在测试方法中,您可以使用String value = System.getProperty("param");
读取它String value = System.getProperty("param");
Maven supports it as well using argLine in some unit test plugins. Maven在某些单元测试插件中使用argLine也支持它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.