I have a web application Maven project, and I want to customize the web.xml file depending on the Profile that is running. I am using the Maven-War-plugin, which allows me
There's a third, compromise option which I implemented in my project. It keeps everything in one web.xml while still making both it and the pom.xml readable. In my case, I had a need to sometimes have security and sometimes have no security, depending on the environment.
So what I did was:
In the pom.xml, define two profiles (or however many you need). Within the profiles, include two properties. When you want security, you leave them empty, like this:
When you want to exclude all of the security, you define them as follows:
<!--
-->
Then, you have a single web.xml file with the following:
${enable.security.start}
...
// all of the XML that you need, in a completely readable format
...
${enable.security.end}
The pom.xml maven-war-plugin has to be configured to use filtering. Mine looks like this:
true
src/main/webapp
**/web.xml
src/main/webapp
src/main/webapp/WEB-INF/web.xml
...
So, basically, when you select the profile to include security, you get two extra CRLF's in your web.xml. When you select the profile to NOT include security, the XML is all still in the web.xml, but it's commented out so it gets ignored. I like this because you don't have to worry about keeping multiple files in sync, yet the XML is still readable (and it's in the web.xml file where people would naturally look for it).