• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kerry Wilson
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic