I have an EAR file which I create with maven, it’s made up of several projects including one war file project. I need to have the build create two ear files which are identical except that one has the kerberos settings disabled in the war file. To disable these settings, I just need to have a section of the web.xml commented out.
What is the best way to do this with Maven? I’d prefer not to create a whole new project which is a duplicate but with the different web.xml file. I’d prefer to have some way to have two web.xml files in the war file project and have the build select which one to use for which ear file. Can anyone suggest how to do this?
Solution 1
You could use a combination of profiles and maven-war-plugin configuration. In the WAR project’s POM, define a default-activated profile and one explicitly activated, they’ll be mutually exclusive this way (unless you have other profiles defined, but then you’ll only have to remember yourself to activate one or the other):
Then, in the build section, define appropriate filtering:
Change your
web.xmlso that in the variable place you have a template marker, like${security.fragment}. Finally, add two property filessecurity.propertiesandno-security.properties`:Invoke Maven either with
-P no-securityor-P security, or without-P. The end.Solution 2
This does not use filtering, but 2 separate
web.xmls. It’s a bit worse then, as it repeats code.Define profiles like in solution 1, but set a different property: location of the
web.xmlin your project. Use this property in the<build>section to indicate it to the maven-war-plugin:In fact, I was struggling with it in my project as I was writing this. I went for the 2nd solution, as the method with resource filtering does not work well with m2eclipse plugin.