简体   繁体   English

如何在intellij中为maven命令行项目添加程序参数?

[英]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配置:

使用junit配置

using maven configuration: 使用maven配置:

使用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.

相关问题 IntelliJ 14中的Maven命令行参数 - Maven command line arguments in IntelliJ 14. 如何在IntelliJ中使用命令行参数构建java项目 - How to build java project with command-line arguments in IntelliJ 如何在使用Maven构建jar时添加命令行参数 - How to add command line arguments when building jar with Maven Maven项目可以在IntelliJ中很好地构建,但不能使用maven命令行 - Maven project builds fine in IntelliJ, but not with maven command line 如何使用带有命令“idea pom.xml”的 Intellij 命令行工具导入 Maven 项目? - How to import a Maven project with Intellij Command line tool with command “idea pom.xml”? 如何从我自己的Maven库中修改一个项目的Maven测试执行阶段的命令行arguments? - How to modify the command line arguments of the Maven test execution phase of a project from my own Maven library? IntelliJ中的命令行,调试/配置中的程序参数字段,如何构造它们? - Command line in IntelliJ, program arguments field in debug/configurations, how to structure them? Maven 项目中的 JUnit 5 测试适用于 IntelliJ,但不适用于命令行 - JUnit 5 tests in Maven Project works in IntelliJ but Not from Command Line 如何将Maven添加到现有的IntelliJ Android项目中 - How to add Maven to an existing IntelliJ Android project 如何从命令行运行 Intellij 项目 - How to run Intellij project from command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM