多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] # 简介 Maven Tomcat插件现在主要有两个版本,tomcat-maven-plugin和tomcat7-maven-plugin,使用方式基本相同。 tomcat-maven-plugin 插件官网: ~~~ http://mojo.codehaus.org/tomcat-maven-plugin/plugin-info.html ~~~ tomcat7-maven-plugin 插件官网: ~~~ http://tomcat.apache.org/maven-plugin.html。 ~~~ # tomcat-maven-plugin ~~~ <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名称。 配置了这个插件之后,项目就是使用你配置的这个插件运行了,项目一启动,就会把你配置的这个 Tomcat 的信息下载下来。也就是说,即使你本地不安装 Tomcat,web 项目也可以运行 几个常用的Goal: ~~~ tomcat:deploy --部署一个web war包 tomcat:reload --重新加载web war包 tomcat:start --启动tomcat tomcat:stop --停止tomcat tomcat:undeploy--停止一个war包 tomcat:run 启动嵌入式tomcat ,并运行当前项目 ~~~ # tomcat7-maven-plugin ~~~xml <build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <!-- 设置编码格式 --> <uriEncoding>UTF-8</uriEncoding> <!-- 控制 tomcat 端口号 --> <port>80</port> <!-- 项目发布到 tomcat 后的名称 --> <!-- 如果写 /,相当于项目发布后的名称为 ROOT --> <!-- 如果写 /abc,相当于项目发布后的名称为 abc --> <path>/</path> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ~~~ 在这里要注意一下,该插件命名方式有些不同,比如启动tomcat ,对应的目标命令是: `tomcat7:run` ,同样,其它命令也是这样,需要更改为:tomcat7:`<插件执行点>` ~~~ tomcat7:deploy --部署一个web war包 tomcat7:reload --重新加载web war包 tomcat7:start --启动tomcat tomcat7:stop --停止tomcat tomcat7:undeploy--停止一个war包 tomcat7:run 启动嵌入式tomcat ,并运行当前项目 ~~~ 如果需要debug,就使用debug as 方式启动项目!