tomcat7-maven-plugin插件的pom.xml依赖为:

<dependency>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
</dependency>

一:直接执行webapp项目

<plugin>
	<groupId>org.apache.tomcat.maven</groupId>
	<artifactId>tomcat7-maven-plugin</artifactId>
	<version>2.2</version>
	<configuration>
		<path>/taobao</path>
		<port>9090</port>
		<uriEncoding>UTF-8</uriEncoding>
	</configuration>
</plugin>

运行 mvn tomcat7:run

訪问 http://127.0.0.1:9090/taobao 就可以訪问


二:部署项目到tomcat

首先。在conf/tomcat-users.xml 文件中面配置

<role rolename="manager-gui"/>
<user username="admin" password="123456" roles="manager,manager-gui"/>


两种方法部署

(1)

直接在pom.xml里面配置插件

<plugin>
	<groupId>org.apache.tomcat.maven</groupId>
	<artifactId>tomcat7-maven-plugin</artifactId>
	<version>2.2</version>
	<configuration>
		<path>/taobao</path>
		<url>http://127.0.0.1:8080/manager/text</url>
		<username>admin</username>
		<password>123456</password>
	</configuration>
</plugin>


(2)

<plugin>
	<groupId>org.apache.tomcat.maven</groupId>
	<artifactId>tomcat7-maven-plugin</artifactId>
	<version>2.2</version>
	<configuration>
		<uriEncoding>UTF-8</uriEncoding>
		<url>http://127.0.0.1:8080/manager/text</url>
		<server>tomcat7</server>
	</configuration>
</plugin>

然后,在settting.xml里面加入

<server>
	<id>tomcat7</id>
	<username>admin</username>
	<password>123456</password>
</server>


注意。上面的/manager/text不能是/manager/html,否则报403错误


最后,运行 mvn tomcat7:deploy就可以部署

訪问地址为:http://127.0.0.1:8080/taobao



maven技术交流 扣扣群  379165311。群里面会不定期分享一些maven文章和教程,欢迎大家增加