maven中tomcat插件的配置

去tomcat官网http://tomcat.apache.org/,左侧栏Apache Tomcat下的Maven Plugin,点进去选择最新版本Version 2.2

通过介绍可知,使用tomcat的maven插件有两种配置方式:

第一种:在pom.xml文件的<build></build>中加入如下配置:

[html]  view plain  copy
  1. <pluginManagement>  
  2.     <plugins>  
  3.         <plugin>  
  4.             <groupId>org.apache.tomcat.maven</groupId>  
  5.             <artifactId>tomcat6-maven-plugin</artifactId>  
  6.             <version>2.2</version>  
  7.         </plugin>  
  8.         <plugin>  
  9.             <groupId>org.apache.tomcat.maven</groupId>  
  10.             <artifactId>tomcat7-maven-plugin</artifactId>  
  11.             <version>2.2</version>  
  12.         </plugin>  
  13.     </plugins>  
  14. </pluginManagement>  
这种配置是针对某一个项目的,只对一个项目生效。

第二种:在maven的setting.xml文件中加入如下配置:

[html]  view plain  copy
  1. <pluginGroups>  
  2.     <pluginGroup>org.apache.tomcat.maven</pluginGroup>  
  3. </pluginGroups>  
这种在maven插件上的配置会对所有的项目起作用。

配置好之后,就可以启动项目看效果了。

使用Maven Build启动项目,Goals那一栏填:

tomcat6:run -Dmaven.tomcat.uriEncoding=UTF-8 -Dmaven.tomcat.path=/ -Dmaven.tomcat.port=8080

或者填:

tomcat7:run -Dmaven.tomcat.uriEncoding=UTF-8 -Dmaven.tomcat.path=/ -Dmaven.tomcat.port=8080

其中,

-Dmaven.tomcat.uriEncoding=UTF-8 这个配置最好始终加上

-Dmaven.tomcat.path=/ 这个配置可以不加,默认使用/${artifactId},此处的artifactId即建pom.xml文件时写的那个artifactId,一般为项目名。如果配置为/的话,届时访问的路径就是hostname:port/,如果配置为/test的话,则访问路径是hostname:port/test,相当于namesapce的作用。

-Dmaven.tomcat.port=8080 这个配置可以设置,默认是8080

以上两种启动方式的区别仅在于使用的tomcat的版本不一样。如果使用tomcat7的话,则如果配置方式是在pom.xml文件中配置的话,则必须配置tomcat7-maven-plugin,否则会BUILD FAILURE;如果配置方式是配置maven的setting.xml文件的话,则无所谓,<pluginGroup>org.apache.tomcat.maven</pluginGroup>这一行的作用是把所有版本的maven的tomcat插件及相关插件都下载下来了。使用tomcat6的话也同理。

猜你喜欢

转载自blog.csdn.net/qq_34627002/article/details/80738007