I am using Maven2 to build a WAR project. Some properties files are dependent on the environment targeted for a release.
I want to deliver, in addition of the WAR, a file called datasource.xml
. This file already exists in my project directory, but contains properties that will be filtered during the build (i.e. some ${foo.bar}
).
In others words, after running the command mvn clean install, I want to see in my target/
directory two files, my-webapp.war
and datasource.xml
.
Note that datasource.xml
must not be included in the my-webapp.war
artifact!
How can I do this?
You can attach additional artifacts using the build-helper-maven-plugin. The configuration below would attach datasource.xml as an additional artifact during the package phase. If that artifact is defined outside of src/main/resources and src/main/webapp it will not be included in the war.
Update: to ensure resource filtering is applied per your comment, you can specify an execution of the resource-plugin's copy-resources goal, specifying filtering to be applied. You can then still attach that filtered artifact using the build-helper-maven-plugin by referencing the corresponding target directory. I've updated the example below to show this usage.
This won't appear in the target folder, but it will be deployed/installed to the repository alongside the war.
The attached artifact can be referenced by defining a dependency with the classifier "datasource". For example:
You could use the the dependency plugin's copy goal to retrieve the artifact and put it wherever it is required as part of your deployment process.