Deploying a Web Application from Maven Build to Remote Tomcat Container with Cargo

Several days ago I had to implement a mechanism that uploads a web application to the running instance of Tomcat. The web application was build using Maven, so the obvious choice was Maven Cargo plugin. The Cargo framework is mostly intended for integration testing, but it’s Maven plugin can do some useful things by the way, as a side effect. There are a lot of documentation on the web about Cargo in general and remote deployment to Tomcat specifically, but I was unable to find the complete example to be taken as-is. So, here it goes!

Prerequisites:
* Your Maven project should be of type war.
* The manager user must have script access to Tomcat Manager application.

Here is the excerpt from the POM file of the project, for future reference.

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.cargo</groupId>
      <artifactId>cargo-maven2-plugin</artifactId>
      <version>1.3.2</version>
      <configuration>

        <!-- Container configuration -->
        <container>
          <containerId>tomcat7x</containerId>
          <type>remote</type>
        </container>

        <!-- Configuration to use with the container -->
        <configuration>
          <type>runtime</type>
          <properties>
            <cargo.hostname>tomcat.example.com</cargo.hostname>
            <cargo.servlet.port>80</cargo.servlet.port>
            <cargo.remote.username>manager</cargo.remote.username>
            <cargo.remote.password>manager</cargo.remote.password>
          </properties>
        </configuration>

        <!-- Deployer configuration -->
        <deployer>
          <type>remote</type>
        </deployer>

        <!-- Deployables configuration -->
        <deployables>
          <deployable>
            <groupId>${project.groupId}</groupId>
            <artifactId>${project.artifactId}</artifactId>
            <type>war</type>
            <properties>
              <context>/${project.artifactId}</context>
            </properties>
          </deployable>
        </deployables>

      </configuration>
    </plugin>
  </plugins>
</build>

After adding this configuration to your project you will be able to deploy your web application to the remote Tomcat by running the following command line:

mvn cargo:redeploy

Enjoy!

2 thoughts on “Deploying a Web Application from Maven Build to Remote Tomcat Container with Cargo

    1. 1. In my case Tomcat listens to HTTP, which is the default. For HTTPS, just add <cargo.protocol>https</cargo.protocol> property to the runtime configuration.
      2. Can you provide more details on that, please?

Leave a Reply