Question: In our company, we have a number different modules constructed as separate wars. 
Each client can pick and choose module he wishes to buy.
Since all modules share same session, security context etc, it makes sense to merge them into a single war. 

Is it possible to automate this process? For example, it should merge web.xml, calculate each wars dependencies, copy files like .jsp and .class etc. By the way, we are using Maven, but were not able to find a solution to this problem.

Answer: 
I recall that the [cargo-maven2-plugin](http://repo1.maven.org/maven2/org/codehaus/cargo/cargo-maven2-plugin/1.0/) 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](https://codehaus-cargo.github.io/cargo/Maven2+plugin.html) has gone missing so I can't give you any more details.

You can check out the [Codehaus Jira](http://jira.codehaus.org/browse/CARGO) site for an understanding of its current status.

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

```xml
<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)
Generally speaking - no, it's not possible. What if you have duplicate JSP names? Servlet names / mappings? Same context listeners loading with different parameters (common if you're using Spring / Struts / etc...)? You get the point. 

In your particular case it may or may not be possible depending on your specific circumstances. Extracting war and copying JSP / classes / libraries over is easy; merging web.xml is a bit more complex as you have to maintain the element order - it may be easier to manually define a "merged" web.xml.