File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Package a different file in .war depending on build environment in maven Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Package a different file in .war depending on build environment in maven" Watch "Package a different file in .war depending on build environment in maven" New topic
Author

Package a different file in .war depending on build environment in maven

Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
Our web app uses a properties file for configuration. We need to use different ones depending on the build environment (dev,testing,staging,live)

I would like to put these in my src/main/resources:
config-dev.properties
config-testing.properties
config-staging.properties
config-live.properties

During packaging I would like the appropriate file to be copied into the /WEB-INF/classes directory.

I guess the build environment would be passed in via command line. Is this the best way to do this? What plugin would handle the file copying?


http://www.goodercode.com
SCJP 1.4
Misha Ver
Ranch Hand

Joined: Mar 03, 2008
Posts: 470
in our case we have files named as


copying all files from work directory except property files and then copy required property file



in some other projects we keep several property files and keep them in the different directories, during build time we copy appropriate one.
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
Thanks a lot, here is what I did:

Three resource directories:
main/resources-development
main/resources-testing
main/resources-production

I setup three maven profiles, when specified they will overwrite any main/resources files with the appropriate ones.

pom.xml:


Profiles are ran using the -P option:

mvn clean package -Ptesting
 
Consider Paul's rocket mass heater.
 
subject: Package a different file in .war depending on build environment in maven