Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

DZone's Guide to

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

Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

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.

<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>tomcat5x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.tomcat.manager.url>
http://localhost:8080/manager
</cargo.tomcat.manager.url>
<cargo.remote.username>
tomcat
</cargo.remote.username>
<cargo.remote.password>
tomcat
</cargo.remote.password>
</properties>
</configuration>
<deployer>
<type>remote</type>
<deployables>
<deployable>
<groupId>
com.theasolutions.airlines
</groupId>
<artifactId>
airlines
</artifactId>
<type>war</type>
</deployable>
</deployables>
</deployer>
</configuration>
</plugin>
</plugins>
</build>

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'?>
<tomcat-users>
<role rolename="manager"/>
<user username="tomcat" password="tomcat" roles="manager"/>
</tomcat-users>

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].

[img_assist|nid=4107|title=|desc=|link=none|align=none|width=505|height=68]

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

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}