making environment specific property files in spring mvc

Rohit Bajaj
Rohit Bajaj used Ask the Experts™
I am having following project structure :
resources->properties ->[,]
I want to create a new project structure in which inside the properties folder there will be following folders
each having there own and file.

I am using maven with spring mvc. How do i make this possible so that when i build the project the right property file gets picked up based on the system environment variables.
eg. if the system environment variable env = DEV then properties files under the dev folder should be used.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Business Systems Analyst / Software Developer
Top Expert 2015
You will need to fiddle with your directory layout a little bit. Are you able to lay it out like this...

     |_  main
                 |_  DEV
                 |              |_  resources
                 |                                    |_  properties
                 |                                                          |_, etc
                 |_  PROD
                 |              |_  resources
                 |                                    |_  properties
                 |                                                          |_, etc
                 |_  QA
                                |_  resources
                                                      |_  properties
                                                                            |_, etc

If so then it is quite easy to configure, you just need to add/merge the following xml into your pom...


Open in new window

I say add or merge because you may already have a <build> section in your pom, and possibly already a resources section. If so you just need to modify what you have got so that it includes the ${env.env} part in the directory path.

If you don't already have these sections, then you can just add them in.

Basically you are just telling the maven-resources-plugin where to find the files that it will operate on. ${ } is used to substitute properties into the configuration. ${basedir} is just a Maven built-in property for the base directory of the project. ${env.env} is how Maven refers to system environment variables, the first "env" tells Maven to look at the system environment, and the second "env" is the name of the environment variable to use.

Refer to the below for information on Maven properties...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial