I'm using different maven profiles to deploy my application to different environments. (With the weblogic-maven-plugin, but I think this is not important)
In the application I use Spring Web Services. Now I'd like to change the endpoint depending on the environment. (The endpoint is defined in Spring's applicationContext.xml)
My idea is to read the value from a property file. This property file will be written (or copied) during Mavens package phase.
Is this a good idea?
If yes: How do I create this property (or the whole file) with maven.
If no: What would be a better aproach to solve this problem?
I achieved something similar, but having the variables in the pom.xml
instead in propreties files. So my properties files have variables that would be changed by Maven in packaging.
First I defined these vars in the profiles section of the pom:
<profiles>
<profile>
<id>dev</id>
<activation><activeByDefault>true</activeByDefault></activation>
<properties>
<props.debug>true</props.debug>
<props.email>false</props.email>
<what.ever.you.want>value for dev profile</what.ever.you.want>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<props.debug>false</props.debug>
<props.email>true</props.email>
<what.ever.you.want>value for prod profile</what.ever.you.want>
</properties>
</profile>
</profiles>
Then activated the maven procesing and filtering of resources. So in your build section:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
Finally I can have "vars" in my properties files, configuration files.
For example, In my project I have a email.properties
file for configuring the emails sending. The property "sendEmail" indicates if I have to send the email (prod profile) or to print it in debug (dev profile). With dev profile this var will be put to false whereas with the profile prod the property will have the true value.
sendEmail=${props.email}
This not only works with properties files, also with XML (I guess with every text file)
The contras are:
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