Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: include resource file based on profile

Tags:

maven

I'm converting an Ant webapp project over to Maven. I have most of it working, but I'm stuck trying to figure out how to copy some resource files from different sources based on the profile.

I have src/main/resources/persistence-{dev, prod}.xml. One of these needs to be included in the war file as WEB-INF/classes/META-INF/persistence.xml.

I would like the dev version to be copied when the dev profile is active, and the prod version when prod is active.

like image 444
George Armhold Avatar asked Sep 08 '11 19:09

George Armhold


People also ask

How do I run a specific profile in Maven?

Profiles can be activated in the Maven settings, via the <activeProfiles> section. This section takes a list of <activeProfile> elements, each containing a profile-id inside. Profiles listed in the <activeProfiles> tag would be activated by default every time a project use it.

Is it possible to add library dependencies inside a profile in Maven?

We can create multiple profiles by declaring id inside <profile> </profile> tag. This <profile> tag should be enclosed between <profiles></profiles> tag. In this above code, We have created a profile with name User1 and declared spring dependency for that specific user.


1 Answers

Just use the maven resources plugin like so http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html and have a property for the file name or extension set in a profile.

like image 71
Manfred Moser Avatar answered Sep 24 '22 06:09

Manfred Moser