Tomcat Remote Deployment using Maven2 & Cargo
Posted by Stephen on May 27, 2009
Gone are the days when you have to copy your WAR into Tomcat/Server’s Webapp directory or use the Tomcat Web UI Admin module to deploy your WAR. With Maven2-plugin-Cargo the deployment becomes one simple maven command.
Add this to your pom.xml : (NOTE – This setting works only for Maven2 and Tomcat6x)
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>false</wait>
<container>
<containerId>tomcat6x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.hostname>${cargo.hostname.dev}</cargo.hostname>
<cargo.servlet.port>${cargo.servlet.port.dev}</cargo.servlet.port>
<cargo.tomcat.manager.url>${cargo.tomcat.manager.url.dev}</cargo.tomcat.manager.url>
<cargo.remote.username>${cargo.remote.username.dev}</cargo.remote.username>
<cargo.remote.password>${cargo.remote.password.dev}</cargo.remote.password>
</properties>
<deployables>
<deployable>
<groupId>Your.Maven.WAR.Project.groupId</groupId>
<artifactId>Your.Maven.WAR.Project.artifactId</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- remote deployment properties -->
<cargo.hostname.dev>Your.Tomcat6x.Server.Hostname(YourTomcat)</cargo.hostname.dev>
<cargo.servlet.port.dev> Your.Tomcat6x.Server.PortNumber(8080)</cargo.servlet.port.dev>
<cargo.tomcat.manager.url.dev>http://YourTomcat:8080/manager</cargo.tomcat.manager.url.dev>
<cargo.remote.username.dev>admin</cargo.remote.username.dev>
<cargo.remote.password.dev>admin</cargo.remote.password.dev>
</properties>
And run the following commands from your project root directory (where pom.xml is located) :
- mvn package (ensure that the war file is created under the target directory)
- mvn cargo:deploy
- mvn cargo:redeploy
- mvn cargo:undeploy
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>false</wait>
<container>
<containerId>tomcat6x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.hostname>${cargo.hostname.dev}</cargo.hostname>
<cargo.servlet.port>${cargo.servlet.port.dev}</cargo.servlet.port>
<cargo.tomcat.manager.url>${cargo.tomcat.manager.url.dev}</cargo.tomcat.manager.url>
<cargo.remote.username>${cargo.remote.username.dev}</cargo.remote.username>
<cargo.remote.password>${cargo.remote.password.dev}</cargo.remote.password>
</properties>
<deployables>
<deployable>
<groupId>Your.Maven.WAR.Project.groupId</groupId>
<artifactId> Your.Maven.WAR.Project.artifactId</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
</configuration>
</plugin>
</plugins>
</build>