![](/img/trans.png)
[英]What is the difference between System.getProperty and properties.getProperty in Java
[英]Maven. Profile. Properties and System.getProperty()
我想使用不同的maven配置文件来为测试需求设置不同的参数。 参数是一个URL。 测试是在Groovy上进行的。 我正在尝试这个:
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<useUrl>http://url</useUrl>
</properties>
</profile>
<profile>
<id>another</id>
<properties>
<useUrl>http://url2</useUrl>
</properties>
</profile>
</profiles>
而groovy代码: baseUrl = System.getProperty("useUrl")
System.getProperty("useUrl")
始终返回'null'。
但是,如果我在surefire插件中进行配置,如下所示:
<systemPropertyVariables>
<baseUrl>${useUrl}</baseUrl>
</systemPropertyVariables>
Code System.getProperty("useUrl")
将完全返回我所期望的 - 活动配置文件中的值( http://url
或http://url2
)。
系统信息:Maven 3.2.5 Windows 8.1 Intellij IDEA 14.0.2
有人可以解释为什么配置文件属性不起作用? 或者我做错了什么? 提前致谢。
Maven属性不是系统属性。
如果需要读取/使用系统属性,则必须在适当的maven插件中明确定义它,例如:
maven-surefire
插件 maven-jetty-plugin
exec-maven-plugin
properties-maven-plugin
用于一般用途
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.