Merging also Webapplications

Lets say you want to create a deployment artifact that consists of one application and one webapplication, which is more a demo use case and should not be the first choice for production, what you can do now is depend on the application, the webapp and on the tomcat artifact from the cms repository or any similar servlet-container artifact, you may create yourself.

What the plugin will do is, extract the application(s) like described in Merging Applications and then extract the servlet container below a configurable root (see Goals) and the webapp artifact below a webapps folder below the servlet container root.

To address the need of reconfiguring the context folder names which are by default determined by the finalName property of the webapps artifact descriptor (pom.xml), you can configure a mapping from of the webapp to the desired context folder name.

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

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

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

  <dependencies>
    <dependency>
      <groupId>com.coremedia.example.project</groupId>
      <artifactId>webapp</artifactId>
      <type>war</type>
      <version>1.0-SNAPSHOT</version>
    </dependency>

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


    <dependency>
      <groupId>com.coremedia.cms</groupId>
      <artifactId>tomcat</artifactId>
      <type>zip</type>
      <version>5.3.1</version>
    </dependency>
  </dependencies>

  <build>
  <finalName>applicationName</finalName>
   <plugins>
      <plugin>
        <groupId>com.coremedia.maven</groupId>
        <artifactId>coremedia-application-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <webapps>
            <webapp>
              <groupId>com.coremedia.example.project</groupId>
              <artifactId>webapp</artifactId>
              <context>my-webapp</context>
            </webapp>
          </webapps>
          <!-- default Values -->
          <tomcatGroupId>com.coremedia.cms</tomcatGroupId>
          <tomcatArtifactId>tomcat</tomcatArtifactId>
          <tomcatPath>tomcat</tomcatPath>
        </configuration>
      </plugin>
   </plugins
  </build>
  ...
</project>

Invoking

mvn package

will generate the ZIP file target/applicationName-1.0-SNAPSHOT.zip. Here are the contents of that ZIP file, with tomcat and webapp content hidden:

applicationName-1.0-SNAPSHOT.zip
  |
  |--META-INF
  |  `--MANIFEST.MF
  |--bin
  |  |--application.jpif
  |--config
  |  `--application
  |     `--spring
  |        |--application.properties
  |        `--application-Context.xml
  |-lib
  | `--application-lib-1.0-SNAPSHOT.jar
  `--tomcat
     `--webapps
        `-my-webapp