Sunday, 21 September 2014

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 war. 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 this question), 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.



<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>




I already saw the answer to the question: How to transform web.xml during packaging with maven?, 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).


No comments:

Post a Comment