There is a third, compromise option that I implemented in my project. It stores everything in one web.xml, while preserving both and readable pom.xml. In my case, I had a need sometimes to have security, and sometimes security, depending on the environment.
So what I did:
In pom.xml, define two profiles (or as many as you like). Inside profiles, two properties are included. When you need security, you leave them blank, for example:
<enable.security.start></enable.security.start> <enable.security.end></enable.security.end>
If you want to exclude all security, you define them as follows:
<enable.security.start><!--</enable.security.start> <enable.security.end>--></enable.security.end>
Then you have one web.xml file with the following:
${enable.security.start} <security-constraint> ...
The mob-war-pom.xml plugin must be configured to use filtering. My looks like this:
<configuration> <webResources> <resource> <filtering>true</filtering> <directory>src/main/webapp</directory> <includes> <include>**/web.xml</include> </includes> </resource> </webResources> <warSourceDirectory>src/main/webapp</warSourceDirectory> <webXml>src/main/webapp/WEB-INF/web.xml</webXml> ...
So basically, when you select a profile to enable security, you get two additional CRLFs in your web.xml. When you select a profile to NOT include security, the XML is still in the web.xml file, but he commented on it, so it is ignored. I like it because you don't have to worry about synchronizing multiple files, but XML is still readable (and it is in the web.xml file, where people will naturally look for it).
Chris Clark Dec 21 '11 at 16:26 2011-12-21 16:26
source share