karthikeyan is a DZone MVB and is not an employee of DZone and has posted 3 posts at DZone. View Full User Profile

How-To: Auto Deploy A Web Application In Tomcat Using The Maven Cargo Plugin

  • submit to reddit

In the previous section we copied the WAR file manually under TOMCAT_HOME/webapps folder. Here we will automate the deployment using cargo plugin. Include the code below in pom.xml under the project root directory [E:\theacodefactory\code\airelinesweb\airlines as in the example considered].

The cargo plugin details should be copied under build/plugins. The values to be changed are in bold. Please change the values as per your requirement.


I have provided a user tomcat with password also as tomcat. The user tomcat has a manager role. This configuration is done in tomcat-users.xml under TOMCAT_HOME/conf folder as in the screenshot below.

<xml version='1.0' encoding='utf-8'?>
<role rolename="manager"/>
<user username="tomcat" password="tomcat" roles="manager"/>

To deploy using the Maven - cargo plugin use the command mvn cargo:deploy as in the screenshot. [To undeploy it is mvn cargo:undeploy. You may also use cargo:redeploy].

Note: The Tomcat server should be started before you execute cargo related Maven commands.

Your rating: None
Published at DZone with permission of karthikeyan Chockalingam, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Alex(JAlexoid) ... replied on Sun, 2008/07/20 - 7:09pm

This thing belongs on http://snippets.dzone.com/

Daniel Wright replied on Fri, 2011/04/29 - 3:53pm

Another sample article about Cargo : Deploying on Tomcat using Maven.
You can easily deploy a webapp using the codehaus tomcat plugin as well. The codehaus plugin is only dedicated to Tomcat with a sample at Deploy on Tomcat using Maven.
If you are using Tomcat 7 be careful will the url change for the webapp manager

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.