Maven Tomcat Deployment using Cargo
Last Updated on Thursday, 16 June 2011 16:55
|
Maven Tomcat Deployment using Cargo plugin
There is a nice plugin for Maven called Cargo which simplifies deployment on different servlet container massively. With Cargo Maven Plugin you can manage different containers which are installed, start, stop fully automatic.
Cargo also performs the deployment of the webproject to the specific container(s). Thus we can really kickstart web development with a properly configured project. If this is not the case step into the tutorial configuring a webproject to simplify team development and testing first.
The project is configured properly for Cargo if the pom-file contains a plugin configuration for the cargo-maven2-plugin artifact which itself contains some container configuration as shown below:
Include the following snippet in the <build><plugins> section of your project's pom.xml-file:
Let's define whee cargo should find the home folder for catalina (Tomcat). Assuming we have a Unix or Mac OSX machine like me, your Maven settings.xml should provide the following Maven profile.
Include the following snippet in the <profiles> section of your project's settings.xml-file:
![]()
This will activate based on OS settings. The Maven profile Unix with be activated because OSX is part of the family unix. catalina.home will be then available as a property.
Deploy a webapp on Tomcat7 with Maven
To try the Cargo deployment simply use:

Undeploy a Maven webapp on Tomcat7
To try the Cargo undeploy simply use:

Tips and Tricks
Define the web context
The context root of a web application determines which URLs Tomcat will delegate to your web application. If your application's context root is webapp then any request for /webapp or /webapp/* will be handled by your application unless a more specific context root exists. If a second web application were assigned the context root myapp/help, a request for /webapp/help/help.jsp would be handled by the second web application, not the first.
Include or update the following snippet in the <deployer> section of your maven cargo plugin definition:

In this definition we are using the artifactId of the project to define the web context






Comments
RSS feed for comments to this post