嗨,我正在研究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) 我正在使用 Eclipse 和 Maven 在移动网页上进行移动自动化测试。
我在 pom.xml 中定义以下内容
<properties>
<MY_VARIABLE>www.google.com/</MY_VARIABLE>
</properties>
Run Code Online (Sandbox Code Playgroud)
但是当我使用这个来调用时
String testurl1 = System.getProperty("MY_VARIABLE");
Run Code Online (Sandbox Code Playgroud)
它似乎总是返回 null。
我还尝试了以下定义变量的方法
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<systemPropertyVariables>
<MY_VARIABLE>www.google.com</MY_VARIABLE>
</systemPropertyVariables>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但仍然得到空值。
我需要一些帮助谢谢。