这篇文章是看的网上的一个问答,比较基础,先存在我的blog里吧
In this tutorial, we will show you how to use Maven-Tomcat plugin to package and deploy a WAR file to Tomcat, both in Tomcat 6 and 7.
Libraries used :
- Maven 3
- Tomcat 6.0.37
- Tomcat 7.0.53
Deploy URL = http://localhost:8080/manager/text
Command =
mvn tomcat7:deploy
Tomcat 6
Deploy URL = http://localhost:8080/manager/
Command = mvn tomcat6:deploy
1. Tomcat 7 Example
This example shows you how to package and deploy a WAR file on Tomcat 7.
1.1 Tomcat Authentication
Add an user with roles manager-gui
and manager-script
.
<?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 Authentication
Add above Tomcat’s user in the Maven setting file, later Maven will use this user to login Tomcat server.
<?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
Declares a Maven Tomcat plugin.
<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>/mkyongWebApp</path>
</configuration>
</plugin>
How it works?
During deployment, it tells Maven to deploy the WAR file to Tomcat server via “http://localhost:8080/manager/text” , on path “/mkyongWebApp“, using “TomcatServer” (in settings.xml) username and password for authentication.
1.4 Deploy to Tomcat
Commands to manipulate WAR file on Tomcat.
mvn tomcat7:deploy
mvn tomcat7:undeploy
mvn tomcat7:redeploy