Ram*_*Ram 16 java eclipse windows pom.xml maven
嗨,我正在研究java maven项目,我必须在pom.xml文件中定义一些变量.
我在我的pom.xml文件中定义了一个变量,如下所示.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<includes>
<include>**/*Test*.java</include>
<include>**/*Tests*.java</include>
<include>**/Test*.java</include>
</includes>
<systemPropertyVariables>
<my.value>NOTNULL</my.value>
</systemPropertyVariables>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
要尝试访问my.value变量,我使用以下Java代码.
String testdata = System.getProperty("my.value");
System.out.println(testdata);
Run Code Online (Sandbox Code Playgroud)
但是,null即使我设置了变量的值,控制台输出也会显示给我.
任何人都可以指出这里有什么问题吗?
提前致谢.
编辑:我也试过声明systemPropertyVariables下,maven-failsafe-plugin但没有变化.
注意:当我尝试转换testdata代码行时,如下所示,
String testdata = System.getProperty("my.value").toString();
Run Code Online (Sandbox Code Playgroud)
我在上面的行中得到一个NullPointer异常.
编辑:很抱歉之前发布此答案..
我使用你提供的插件... /插件代码运行它作为JUnit测试,但这是我的控制台输出..
21 Oct 2014 12:36:56,973 main INFO s.MyClass - Default Implicit timeout set in Driver to: 100
21 Oct 2014 12:36:56,973 main INFO s.MyClass - Default URL for server is set to: http://localhost:8080
---- null
Run Code Online (Sandbox Code Playgroud)
URL是我试图从pom.xml文件中检索的,我写的条件是
如果变量中的值为空,则以$ {开始返回localhost:8080,否则返回url.
所以,如果你能在这里指出我的错误
对我的作品与maven-3.2.3上Windows同JDK 1.6.0_67
用maven-archetype-quickstart... 创建了一个项目
添加了相关的pom行...将surefire示例与上面问题中的特定行结合在一起。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<systemPropertyVariables>
<my.value>NOTNULL</my.value>
<buildDirectory>${project.build.directory}</buildDirectory>
</systemPropertyVariables>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
AppTest.java中的相关行
/**
* Rigourous Test :-)
*/
public void testApp()
{
System.out.println(System.getProperty("my.value"));
System.out.println(System.getProperty("buildDirectory"));
assertTrue( true );
}
Run Code Online (Sandbox Code Playgroud)
相关输出 mvn test
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.mycompany.app.AppTest
NOTNULL
C:\Users\raghu\Documents\GitHub\mvn-examples\test-properties\target
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 sec - in c
om.mycompany.app.AppTest
Run Code Online (Sandbox Code Playgroud)
这是github中的项目。