行家。轮廓。属性和 System.getProperty()
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")
总是 returns 'null'.
但是如果我像这样在 surefire 插件中进行配置:
<systemPropertyVariables>
<baseUrl>${useUrl}</baseUrl>
</systemPropertyVariables>
代码 System.getProperty("useUrl")
将 return 完全符合我的预期 - 来自活动配置文件(http://url
或 http://url2
)的值。
系统信息:
行家 3.2.5
Windows 8.1
Intellij IDEA 14.0.2
有人可以解释为什么配置文件属性不起作用吗?或者我做错了什么?
提前致谢。
Maven 属性不是系统属性。
如果您需要 read/use 系统属性,您必须在适当的 Maven 插件中明确定义它,例如:
maven-surefire
单元测试插件
maven-jetty-plugin
用于 Jetty servlet 容器
exec-maven-plugin
运行 您的应用程序使用 maven
properties-maven-plugin
一般用途
我想使用不同的 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")
总是 returns 'null'.
但是如果我像这样在 surefire 插件中进行配置:
<systemPropertyVariables>
<baseUrl>${useUrl}</baseUrl>
</systemPropertyVariables>
代码 System.getProperty("useUrl")
将 return 完全符合我的预期 - 来自活动配置文件(http://url
或 http://url2
)的值。
系统信息: 行家 3.2.5 Windows 8.1 Intellij IDEA 14.0.2
有人可以解释为什么配置文件属性不起作用吗?或者我做错了什么? 提前致谢。
Maven 属性不是系统属性。
如果您需要 read/use 系统属性,您必须在适当的 Maven 插件中明确定义它,例如:
maven-surefire
单元测试插件maven-jetty-plugin
用于 Jetty servlet 容器exec-maven-plugin
运行 您的应用程序使用 mavenproperties-maven-plugin
一般用途