I want to use a variable which has different values in the properties file depending on the environment. I want to use that variable in my pom.xml.
Add a set of appropriate <profile>
entries in your pom and include the variables you need in a list of <properties>
:
<profile>
<id>Dev</id>
<properties>
<proxyServer>dev.proxy.host</proxyServer>
<proxyPort>1234</proxyPort>
</properties>
</profile>
<profile>
<id>QA</id>
<properties>
<proxyServer>QA.PROXY.NET</proxyServer>
<proxyPort>8888</proxyPort>
</properties>
</profile>
<profile>
<id>Prod</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<proxyServer>PROD.PROXY.NET</proxyServer>
<proxyPort>8080</proxyPort>
</properties>
</profile>
Notice that the Prod
profile has been tagged: <activeByDefault>
.
Within the properties file, use pom-style variable demarcation to add variable value placeholders, matching the <property>
tag names used in the pom:
proxyServer=${proxyServer}
proxyPort=${proxyPort}
Within the pom's <build>
section, add a <resources>
entry (assuming that your properties are in the src/main/resources directory), include a <filtering>
tag, and set the value to: true
:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>settings.properties</include>
</includes>
</resource>
</resources>
Then, when you run your Maven build, the demarcated property values will be replaced with the values that are defined in the pom <profile>
entries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With