Maven 集成Tomcat插件

tomcat-maven-plugin  插件使用

配置

在pom.xm 加入以下xml。

<plugin>
      <groupId>org.codehaus.mojo</groupId>
  <artifactId>tomcat-maven-plugin</artifactId>
  <version>1.1</version>
  <configuration>
  <path>/wp</path>
  <port>8080</port>
  <uriEncoding>UTF-8</uriEncoding>
  <url>http://localhost:8080/manager/html</url>
  <server>tomcat6</server>
  </configuration>
</plugin>

简要说明一下:

path  是访问应用的路径

port 是tomcat 的端口号

uriEncoding  URL按UTF-8进行编码,这样就解决了中文参数乱码。

Server 指定tomcat名称。

配置就这么简单,基本搞掂,下面看看如何使用。

插件运行

 

如果Eclipse 安装了Maven插件,选 择pom.xml文件,击右键——>选择 Run As——> Maven build 。

image

如果是第一次运行,会弹出下面对话框。在Goals框加加入以下命令: tomcat:run

image

这样Tomcat 插件就可以运行。

下面介绍几个常用的Goal

命令 描述
tomcat:deploy 部署一个web war包
tomcat:reload 重新加载web war包

tomcat:start

启动tomcat

tomcat:stop

停止tomcat

tomcat:undeploy

停止一个war包
tomcat:run 启动嵌入式tomcat ,并运行当前项目

tomcat7-maven-plugin 使用

配置

 

两个插件使用方法基本一样,同样需要在pom.xml引用该插件,需要增加以下配置

<plugin>
  <groupId>org.apache.tomcat.maven</groupId>
  <artifactId>tomcat7-maven-plugin</artifactId>
  <version>2.1</version>
  <configuration>
  <port>9090</port>
  <path>/mgr</path>
  <uriEncoding>UTF-8</uriEncoding>
  <finalName>mgr</finalName>
  <server>tomcat7</server>
  </configuration>
</plugin>

具体配置一样。

插件使用 

在这里要注意一下,该插件命名方式有些不同,比如启动tomcat ,对应的目标命令是: tomcat7:run ,同样,其它命令也是这样,需要更改为:tomcat7:<插件执行点>

OK,配置就这么简单,如果需要在 tomcat 跟踪联调,可以用Dubug 方式启动maven命令。如下图

image

原文地址:https://www.cnblogs.com/austinspark-jessylu/p/6802315.html