Merging Applications

Lets say you want to create a deployment artifact that consists of two applications with merely the same library stack and no conflicting dependency versions. You can achieve this simply by depending on both artifacts. What happens is that both artifacts are extracted and their dependencies will be copied to the shared lib folder.

To illustrate, here's the pom.xml for our project:

<project>
  ...
  <groupId>com.coremedia.example.project</groupId>
  <artifactId>example-merged-application</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>coremedia-application</packaging>

  <name>Example Application merged with another Application Project</name>

  <dependencies>
    <dependency>
      <groupId>com.coremedia.example.project</groupId>
      <artifactId>application-one</artifactId>
      <type>coremedia-application</type>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>com.coremedia.example.project</groupId>
      <artifactId>application-one</artifactId>
      <type>pom</type>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>com.coremedia.example.project</groupId>
      <artifactId>application-two</artifactId>
      <type>coremedia-application</type>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>com.coremedia.example.project</groupId>
      <artifactId>application-two</artifactId>
      <type>pom</type>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>

  <build>
   <finalName>applicationName</finalName>
   <plugins>
      <plugin>
        <groupId>com.coremedia.maven</groupId>
        <artifactId>coremedia-application-maven-plugin</artifactId>
        <extensions>true</extensions>
      </plugin>
   </plugins
  </build>
  ...
</project>

As you can see the usage of dependencies is similar as with the maven-war-plugin, as you have to declare also a dependency to the pom of the artifact. The reason for this is that all dependencies are only attached to the pom but not to the coremedia-application(zip) artifact.

The project's structure looks like this:

 .
 |-- pom.xml
 `-- src
     `-- main
         `--app
            `--config
               |--application-one
               |  `--spring
               |     |--application-one.properties
               |     `--application-one-Context.xml
               `--application-two
                  `--spring
                     |--application-two.properties
                     `--application-two-Context.xml

Invoking

mvn package

will generate the ZIP file target/applicationName-1.0-SNAPSHOT.zip. Here are the contents of that ZIP file:

applicationName-1.0-SNAPSHOT.zip
  |
  |--META-INF
  |  `--MANIFEST.MF
  |--bin
  |  |--application-one.jpif
  |  `--application-two.jpif
  |--config
  |  |--application-one
  |  |  `--spring
  |  |     |--application-one.properties
  |  |     `--application-one-Context.xml
  |  `--application-two
  |     `--spring
  |        |--application-two.properties
  |        `--application-two-Context.xml
  |
  `-lib
    |--application-one-lib-1.0-SNAPSHOT.jar
    |--application-one-config-1.0-SNAPSHOT.jar
    |--application-two-lib-1.0-SNAPSHOT.jar
    `--application-two-config-1.0-SNAPSHOT.jar