Auto Deploy Web Application In Tomcat

How to auto deploy web application in Tomcat ?? Here is the solution… The deployment of the web application is automated using maven Cargo plugin.

Tomcat – 6.0.36
Maven – 2.2.1
java – 1.6

Add the following code to pom.xml in your project and replace the project name, path to web directory, package name as highlighted in the code.

<build>
  <finalName>{your.project.name}</finalName>
<plugins>
  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.1.1</version>
  <configuration>
  <webappDirectory>{your.project.webapp.directory}</webappDirectory>
  </configuration>
  </plugin>
  <plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
  <container>
  <containerId>tomcat6x</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>
  {project.package}
  </groupId>
  <artifactId>
  {your.project.name}
  </artifactId>
  <type>war</type>
  </deployable>
  </deployables>
  </deployer>
  </configuration>
  </plugin>
</plugins>
</build>

Add following to  tomcat-users.xml in  tomcat/conf

<tomcat-users>
  <role rolename="manager"/>
  <user username="tomcat" password="tomcat" roles="manager"/>
</tomcat-users>

Maven Commands to deploy/redeploy the web application is,
deploy – mvn cargo:deploy
redeploy – mvn cargo:redeploy

Posted in Web

Tags:

Permalink 2 Comments

Blog Stats

  • 38,691 hits