making environment specific property files in spring mvc

HI,
I am having following project structure :
resources->properties ->[database.properties, log4j.properties]
I want to create a new project structure in which inside the properties folder there will be following folders
DEV
PROD
QA
each having there own database.properties and log4j.properties 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.

Thanks
Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
You will need to fiddle with your directory layout a little bit. Are you able to lay it out like this...

src
     |_  main
                 |_  DEV
                 |              |_  resources
                 |                                    |_  properties
                 |                                                          |_  database.properties, etc
                 |_  PROD
                 |              |_  resources
                 |                                    |_  properties
                 |                                                          |_  database.properties, etc
                 |_  QA
                                |_  resources
                                                      |_  properties
                                                                            |_  database.properties, etc



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

    <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/${env.env}/resources/</directory>
            </resource>
        </resources>
    </build>

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.

Explanation...
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...
https://maven.apache.org/pom.html#Properties
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.