我有一个maven项目,在pom.xml中设置了不同的配置文件,具有不同的值.但我不知道如何通过java代码访问配置文件中设置的值.例如-
我的pom.xml:
<profile>
<id>scaler</id>
<properties>
<user>xxxxxxx</user>
<secret>yyyyyyyy</secret>
<proxyHost>172.19.17.13</proxyHost>
<proxyPort>9444</proxyPort>
<environment>SCALER</environment>
</properties>
</profile>
Run Code Online (Sandbox Code Playgroud)
Java代码 -
String serviceurl = "http://"<proxyhost>":<proxyPort>/";
Run Code Online (Sandbox Code Playgroud)
在上面的java代码中,我想使用代理主机作为172.19.17.13&port为9444,如pom.xml中定义但是如何从pom中访问这些值?我将感谢你的帮助
小智 5
您应该使用 Maven 过滤功能。
http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
只需在 src/main/resources 中添加一个带有一些占位符的属性文件:
key=${myvalue}
Run Code Online (Sandbox Code Playgroud)
thenmyvalue应该被定义为 pom.xml 中的一个属性
请务必激活您的资源过滤器:
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2932 次 |
| 最近记录: |