Package a Maven-transformed web.xml in the final war


I want to make Maven process the web.xml file prior to including it in the final <em>war</em>. This is going to be profile-dependent, so editing the source XML is not an option.

I'm using the xml-maven-plugin to add the new elements to the file (you can get additional details in <a href="https://stackoverflow.com/q/25957167/3127111" rel="nofollow">this question</a>), and had success in achieving it, having the plugin put the trasformed file in target/generated-resources/xml/xslt (I guess that's a default destination directory).

Now I need to instruct Maven to pick up that transformed file (and not the one in src/main/webapp/WEB-INF/) when packaging the application.

But I'm stuck here, I have no idea how to go further.

As a side note, I bound the xml-maven-plugin to the process-resources phase. The whole plugin configuration follows at the end.

Feel free to suggest another folder structure, configuration changes, or even if this isn't the right way to do it, etc — this is a test setup, I'm using it to learn Maven.

<pre class="lang-xml prettyprint-override"> <profile> <id>release-production</id> <activation> <activeByDefault>true</activeByDefault></activation> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>xml-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <goals> <goal>transform</goal> </goals> <phase>process-resources</phase> </execution> </executions> <configuration> <transformationSets> <transformationSet> <dir>src/main/webapp/WEB-INF</dir> <includes> <include>web.xml</include> </includes> <stylesheet>src/main/resources-xml/webxml-transform.xsl</stylesheet> </transformationSet> </transformationSets> </configuration> </plugin> </plugins> </build> </profile> <hr />

I already saw the <a href="https://stackoverflow.com/a/14366116/3127111" rel="nofollow">answer</a> to the question: <a href="https://stackoverflow.com/q/14350349/3127111" rel="nofollow">How to transform web.xml during packaging with maven?</a>, but I need to add whole XML elements to the web.xml, so I guess that using properties won't work here (at least, I had an error when I tried to define a property with XML content).


It was easier than I thought (although I guess this could be done with a simpler configuration).<br /> I'm open to suggestions, of course.

<h2>First step: configure a custom output directory for the xml transformer</h2>

The xml-maven-plugin has an (undocumented?) additional property: <a href="http://mojo.codehaus.org/xml-maven-plugin/apidocs/org/codehaus/mojo/xml/transformer/TransformationSet.html#setOutputDir(java.io.File)" rel="nofollow"><outputDir /></a> in its TransformationSet element (here's my full plugin configuration).

<pre class="lang-xml prettyprint-override"><plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>xml-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <goals> <goal>transform</goal> </goals> <phase>process-resources</phase> </execution> </executions> <configuration> <transformationSets> <transformationSet> <dir>src/main/webapp/WEB-INF</dir> <includes> <include>web.xml</include> </includes> <stylesheet>src/main/resources-xml/webxml-transform.xsl</stylesheet> <outputDir>target/generated-resources</outputDir> </transformationSet> </transformationSets> </configuration> </plugin> <h2>Second step: configure the <em>war</em> plugin to read another web.xml file</h2>

Tell the maven-war-plugin where the new (transformed) web.xml file is:

Having bound the xml-maven-plugin to the <em>process-resources</em> phase, I know that the transformed web.xml will be there when the <em>war</em> is packaged.

<pre class="lang-xml prettyprint-override"><plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <webXml>target/generated-resources/web.xml</webXml> </configuration> </plugin>


  • can't get the image to rotate in center in Qt
  • Getting “node stack overflow” when cbind multiple sparse matrices
  • Google app engine task queue and users service
  • XslTransform with xml-stylesheet
  • ContextNotActiveException in simple Faces Flow with CDI
  • Cloning a Windows Store app - What should be changed?
  • Grails 2.1.1 - How to develop a plugin with an AstTransformer?
  • Why async.map function works with the native fs.stat function?
  • How to implement xsl
  • Creating grails binary plugin results in jar file wich contains all groovy files with comments
  • Merging two XPathDocuments using XmlCompiledTransform
  • AWS Elastic Beanstalk - changing owner of webapp folder
  • HttpServletRequest getPart(\") not found
  • Duplicated password validation messages ONLY IF new password is 1 char long
  • Failed to read schema document 'http://www.springframework.org/schema/tool/spring-tool-4.1.xsd&
  • call a java program from a webapp in tomcat server - the java program is out side of tomcat server
  • How do I refer to a client_deploy.wsdd file that's in WEB-INF?
  • How to access meteor package name inside package?
  • XSLT foreach repeating nodes to flat
  • netsh acl setting (need alternative method - registry settings?)
  • how to set variables in a php include file?
  • How to get current document uri in XSLT?
  • How to view images from protected folder with php?
  • Display images in Django
  • Reading JSON from a file using C++ REST SDK (Casablanca)
  • Recording logins for password protected directories
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Spray.io: When (not) to use non-blocking route handling?
  • Resize panoramic image to fixed size
  • output of program is not same as passed argument
  • Modifying destination and filename of gulp-svg-sprite
  • Importing jscolor library in angular 2
  • Akka Routing: Reply's send to router ends up as dead letters
  • GridView Sorting works once only
  • Is there a mandatory requirement to switch app.yaml?
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • unknown Exception android
  • Checking variable from a different class in C#
  • UserPrincipal.Current returns apppool on IIS