Maven集成tomcat来启动服务,即使不是web项目同样可以将项目在tomcat中进行启动
1、环境介绍
maven:apache-maven-3.0.3
tomcat:apache-tomcat-6.0.32
jdk:jdk1.5.0_11
eclipse:3.7.2
2、配置tomcat-maven-plugin
在pom.xml中加入如下配置
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>tomcat-maven-plugin</artifactId>
- <version>1.1</version>
- <configuration>
- <server>tomcat-6.0.32</server>
- <url>http://127.0.0.1:8080/manager</url>
- <uriEncoding>${encoding}</uriEncoding>
- <warSourceDirectory>WebContent</warSourceDirectory>
- </configuration>
- </plugin>
说明:
- tomcat-maven-plugin现在已拆分成tomcat7-maven-plugin和tomcat6-maven-plugin了,而groupId也由org.codehaus.mojo改为org.apache.tomcat.maven。
3、集成tomcat测试的方法
方法一(推荐):
运行mvn tomcat:run命令,启动内嵌的tomcat进行测试
1) 可在命令行直接运行mvn tomcat:run命令
2) 如果使用eclipse,可通过maven的eclipse插件m2e新增一个maven build运行tomcat:run命令,如图:
此文是摘录文献