Changing resources inside military overlay in maven

I have this setting now:

Project A displays a military file - it has a configuration file (WEB-INF / web.xml). We deliver this using a commented configuration section, which is unpacked manually when the project is deployed in a specific environment.

The needs of the project have changed - and I need Project A to be built without this part of the configuration as a whole; and I need another project (Project B) that will be built with this configuration section (enabled, not commented out).

Instead of having the file exist in both projects (dual maintenance), I was hoping that project B depended on project A (via a military overlay), and then use the maven-config-processor plugin to add my special config to WEB-INF / web .xml, then repackage the war file.

This does not work, though - a configuration modification may work if the target already exists (i.e., after the previous launch), but when I run everything together, overlapping and repacking in a new war happen together - and I can’t figure out how to make the plugin config-processor work in the middle. Basically, the default order ends with a “configuration processor” (which fails because the overlay has not happened yet), then “war” (all as one unit). I can’t make the configuration processor after the overlay, but before the war it was completely packed.

Several people on the Internet over the past few years have asked if there is a way to implement the plugin between the steps “unzip the overlay” and “repack the military file”, but no one seemed to answer this question in any case, Any ideas?

+7
source share
2 answers

Since military impositions and packaging for war all seem to occur as part of one goal, I don’t think there is a way to get to the center. As a workaround, you can extract web.xml at an earlier stage and process it. The maven-dependency plugin can be used in Project B to extract web.xml from Project A to the working directory, then run maven-config-processor-plugin on web.xml and put the result in another place, and then instruct maven-war -plugin to include processed web.xml before overlay. In Project B POM:

 <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.4</version> <executions> <!-- Extract web.xml from Project A --> <execution> <id>unpack-webxml</id> <phase>generate-resources</phase> <goals> <goal>unpack</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>your.group</groupId> <artifactId>project.a</artifactId> <version>...</version> <type>war</type> <overWrite>true</overWrite> <outputDirectory>${project.build.directory}/myconfig/work</outputDirectory> <includes>WEB-INF/web.xml</includes> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> <plugin> <groupId>com.google.code.maven-config-processor-plugin</groupId> <artifactId>maven-config-processor-plugin</artifactId> <version>2.0</version> <executions> <!-- Process extracted web.xml and place in temp build directory --> <execution> <id>process-webxml</id> <goals> <goal>process</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/myconfig/build</outputDirectory> <transformations> <transformation> <input>${project.build.directory}/myconfig/work/WEB-INF/web.xml</input> <output>WEB-INF/web.xml</output> <!-- your transformation config --> </transformation> </transformations> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <webResources> <!-- Instruct war plugin to include temp build directory in webapp --> <resource> <directory>${project.build.directory}/myconfig/build</directory> <includes> <include>**</include> </includes> </resource> </webResources> <overlays> <!-- Overlay customization if needed --> </overlays> </configuration> </plugin> </plugins> 

As far as I can tell, the military plugin includes first webResources , then src/main/webapp , and then overlays.

I am not familiar with maven-config-processor-plugin, so I apologize if my configuration is not correct there.

+5
source

You can use the unpack target maven-dependency-plugin to get project A, to get web.xml locally, and then convert it and specify maven-war-plugin to convert web.xml .

  <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>unpack</id> <phase>generate-resources</phase> <goals> <goal>unpack</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>org.test</groupId> <artifactId>test-war1</artifactId> <version>0.0.1-SNAPSHOT</version> <type>war</type> </artifactItem> </artifactItems> <outputDirectory>${project.build.directory}/wars</outputDirectory> </configuration> </execution> </executions> </plugin> <plugin> <groupId>com.google.code.maven-config-processor-plugin</groupId> <artifactId>maven-config-processor-plugin</artifactId> <version>2.0</version> <configuration> <!-- configure to transform file ${project.build.directory}/wars/WEB-INF/web.xml into ${project.build.directory}/transformed/web.xml --> </configuration> <executions> <execution> <goals> <goal>process</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.2</version> <configuration> <warSourceDirectory>src/main/webapp</warSourceDirectory> <webXml>${project.build.directory}/transformed/web.xml</webXml> </configuration> </plugin> </plugins> </build> 
+4
source

All Articles