How to merge wars into one?

Granted the risks mentioned by djna and ChssPly76, you may be able to achieve this by using overlays with the Maven WAR plugin. This will require you to separate out servlet mappings to ensure you don't have any URL collisions and the like, but it might do the trick.

Basically, you create a module with multiple WAR dependencies and use the plugin to merge them into a new one.


I recall that the cargo-maven2-plugin has an uberwar mojo. I've not used it but I understand it is intended to merge wars, though you need to be careful to avoid conflicts.

A quick scan of the source indicates you define a merge descriptor to determine how to merge the wars. Unfortunately the documentation site has gone missing so I can't give you any more details.

You can check out the Codehaus Jira site for an understanding of its current status.

To use the plugin you'd specify the configuration something like this:

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.cargo</groupId>
      <artifactId>cargo-maven2-plugin</artifactId>
      <version>1.0</version>
      <extensions>true</extensions>
      <configuration>
      <descriptor>merge.xml</descriptor>
      </configuration>
    </plugin>
  </plugins>
</build>
<dependencies>
  <dependency>
    <groupId>project1.groupId</groupId>
    <artifactId>project1</artifactId>
    <type>war</type>
    <version>1.0.0</version>
  </dependency>
  <dependency>
    <groupId>project2.groupId</groupId>
    <artifactId>project2</artifactId>
    <type>war</type>
    <version>1.2.0</version>
  </dependency>
</dependencies> 

(still looking for a merge.xml example)


It's clearly possible to do this, but I think that you would be better off working on a single WAR in the first place. Late "pick-and-mix" of WAR contents sounbds like a support nightmare to me.