• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
"To do good, you actually have to do something." -- Yvon Chouinard
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic