In this tutorial, we will learn how to use the Maven Tomcat plugin to package and deploy a war file to Tomcat (Tomcat 6 and 7.
To use the tool:
- Maven 3
- Tomcat 6.0.37
- Tomcat 7.0.53
Tomcat 7
Publish URL =
Http://localhost:8080/manager/text
Command = MVN Tomcat7:deploy
Tomcat 6
Publish URL = http://localhost:8080/manager/
Command = MVN Tomcat6:deploy
1. Tomcat 7 Example
This example shows how to package and deploy the war file in Tomcat7.
1.1 TOMCAT Certification
Add users who have the role manager GUI and administrative scripts.
%tomcat7_path%/conf/tomcat-users.xml
<?xml version= ' 1.0 ' encoding= ' utf-8 '? ><tomcat-users><role rolename= "Manager-gui"/><role Rolename= "Manager-script"/><user username= "admin" password= "password" roles= "Manager-gui,manager-script"/ ></tomcat-users>
1.2 Maven Certification
The Tomcat user who added the Maven settings file above is followed by Maven using this user to log on to the Tomcat server.
%maven_path%/conf/settings.xml
<?xml version= "1.0" encoding= "UTF-8"? ><settings ...><servers> <server><id> tomcatserver</id><username>admin</username><password>password</password></ Server></servers></settings>
1.3 Tomcat7 Maven Plugin
Declare a maven tomcat plugin.
Pom.xml
<plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin< /artifactid><version>2.2</version><configuration><url>http://localhost:8080/manager /text</url><server>tomcatserver</server><path>/yiibaiwebapp</path></ Configuration></plugin>
How does that work?
During the deployment process, it tells Maven to deploy the WAR file Tomcat server, "Http://localhost:8080/manager/text", on the Path "/yiibaiwebapp", using "Tomcatserver" ( settings.xml) user name and password to authenticate.
1.4 Publishing to Tomcat
The following command is used to manipulate the Tomcat war file.
MVN tomcat7:deploy mvn tomcat7:undeploy mvn tomcat7:redeploy
Example
> MVN tomcat7:deploy ... [INFO] Deploying War to http://localhost:8080/yiibaiWebAppUploading:http://localhost:8080/manager/text/deploy?path=% 2fyiibaiwebapp&update=trueuploaded:http://localhost:8080/manager/text/deploy?path=%2fyiibaiwebapp& Update=true (13925 KB at 35250.9 kb/sec) [INFO] tomcatmanager status code:200, Reasonphrase:ok[info] ok-deployed applicat Ion at Context Path/yiibaiwebapp[info]------------------------------------------------------------------------[ Info] BUILD Success[info]------------------------------------------------------------------------[INFO] Total time : 8.507 S[info] finished at:2015-08-05t11:35:25+08:00[info] Final Memory:28m/308m[info]----------------------------- -------------------------------------------
2. Tomcat 6 Example
This example shows how to package and deploy the war file in Tomcat6. These steps are the same as TOMCAT7, except that the deployment URL and command name are different.
2.1 TOMCAT Certification
%tomcat6_path%/conf/tomcat-users.xml
<?xml version= ' 1.0 ' encoding= ' utf-8 '? ><tomcat-users><role rolename= "Manager-gui"/><role Rolename= "Manager-script"/><user username= "admin" password= "password" roles= "Manager-gui,manager-script"/ ></tomcat-users>
2.2 Maven Certification
%maven_path%/conf/settings.xml
<?xml version= "1.0" encoding= "UTF-8"? ><settings ...><servers> <server><id> tomcatserver</id><username>admin</username><password>password</password></ Server></servers></settings>
2.3 Tomcat6 Maven Plugin
Pom.xml
<plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat6-maven-plugin< /artifactid><version>2.2</version><configuration><url>http://localhost:8080/manager </url><server>tomcatserver</server><path>/yiibaiwebapp</path></configuration ></plugin>
2.4 Publishing to Tomcat
MVN tomcat6:deploy mvn tomcat6:undeploy mvn tomcat6:redeploy
Example
> MVN tomcat6:deploy ... [INFO] Deploying War to http://localhost:8080/yiibaiWebAppUploading:http://localhost:8080/manager/deploy?path=% 2fyiibaiwebappuploaded:http://localhost:8080/manager/deploy?path=%2fyiibaiwebapp (13925 KB at 32995.5 KB/sec) [INFO] ------------------------------------------------------------------------[INFO] BUILD Success[info]-------------- ----------------------------------------------------------[INFO] Total time:22.652 s[info] finished at: 2014-08-05t12:18:54+08:00[info] Final Memory:30m/308m[info]----------------------------------------------------- -------------------
Reference
- Apache Tomcat 7 Manager App How-to
- Apache Tomcat 6 Manager App How-to
- Tomcat Maven Plugin
- Tomcat Maven Plugin–context Goals
Tags: deploying Maven War Files Tomcat
This site is reproduced in addition to the article, are the original site or compiled
Welcome any form of reprint, but please be sure to indicate the source, respect for the work of others to create excellent examples of the tutorial
Reprint Please specify: Article reprinted from: http://www.yiibai.com/maven/deploy-maven-based-war-file-to-tomcat.html
Maven learns---Deploy MAVEN-based war files to Tomcat