我需要用maven执行一些测试,并从命令行传递一个参数.
我的java代码应该获取参数:System.getenv("my_parameter1");
我在pom.xml文件中定义参数,如下例所示:(后者,我修改pom.xml以从公共行获取参数mvn clean install -Dmy_parameter1 = value1)
但它不起作用; System.getenv("my_parameter1")返回null.我应该如何在pom.xml文件中定义参数?
的pom.xml
<project>
...
<profiles>
<profile>
<properties>
<my_parameter1>value1</my_parameter1>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>slowTest</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*Test.java</include>
<include>**/*TestSlow.java</include>
</includes>
<properties>
<my_parameter1>value1</my_parameter1>
</properties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Run Code Online (Sandbox Code Playgroud) 我需要创建 2 个 Maven 配置文件,可以在其中设置两个不同的系统属性。这些配置文件仅用于设置系统属性,与任何插件无关。
喜欢
<profile>
<id> profile1 to set system property 1</id>
.... set system property1
</profile>
<profile>
<id> profile2 to set system property 2</id>
.... set system property2
</profile>
Run Code Online (Sandbox Code Playgroud)