原文同步至:http://www.waylau.com/tomcat-maven-plugin/
Apache Tomcat 的 Maven 插件提供了 goal,实现将 Apache Tomcat servlet 容器整合进 WAR 项目。你可以通过 Apache Maven 运行 WAR 项目而无需部署 WAR 文件到 Apache Tomcat 的实例。
详见下面网站:
- Trunk (开发环境下)
- Version 2.2 (2013-11-11)
- Version 2.1 (2013-02-25)
- Version 2.0 (2012-09-14)
- Version 2.0-beta-1 (2012-02-01)
源码:
svn 路径:
http://svn.apache.org/repos/asf/tomcat/maven-plugin/trunk/
功能:
- 支持 Apache Tomcat7
- 构建一个可执行的 War/Jar
使用
自从版本 2.0-beta-1以后, tomcat mojos 更名为 tomcat6 和 tomcat7,使用配置如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
org.apache.tomcat.maven
tomcat6-maven-plugin
2.3
-SNAPSHOT
org.apache.tomcat.maven
tomcat7-maven-plugin
2.3
-SNAPSHOT
|
或者添加 groupId 到你的 settings.xm
|
1
2
3
4
5
|
....
org.apache.tomcat.maven
....
|
在 tomcat 发布不显示项目名称
配置如下
|
1
2
3
4
5
6
7
8
|
org.apache.tomcat.maven
tomcat7-maven-plugin
2.2
/
|
Context Goals
部署 WAR 项目
在 tomcat:deploy 部署后,再次部署 WAR 执行:
|
1
|
mvn
package
tomcat6/
7
:redeploy
|
在执行 tomcat:exploded 后,再次部署 WAR 执行:
|
1
|
mvn war:exploded tomcat6/
7
:redeploy
|
在执行 tomcat:inplace 后,再次部署 WAR 执行:
|
1
|
mvn war:inplace tomcat6/
7
:redeploy
|
在执行 tomcat:deploy 后,再次部署 context.xml 文件执行:
|
1
|
mvn tomcat6/
7
:redeploy
|
注意: context.xml指定 docBase后 ,还需要像上面那样调用 war:exploded或者war:inplace
移除部署 WAR 项目
|
1
|
mvn tomcat6/
7
:undeploy
|
启动 WAR 项目
|
1
|
mvn tomcat6:start
|
停止 WAR 项目
|
1
|
mvn tomcat6:stop
|
列出会话统计表
|
1
|
mvn tomcat6:sessions
|
Container Goals
列出部署的应用s
|
1
|
mvn tomcat6:list
|
列出服务器信息
|
1
|
mvn tomcat6:info
|
列出 JNDI 资源
列出 Tomcat 版本, 操作系统, 和 JVM 等信息
|
1
|
mvn tomcat6:resources
|
另外,列出特定类型你可以只输入 JNDI 资源类型:
|
1
|
mvn -Dmaven.tomcat.type=my.
class
.name tomcat6:resources
|
列出安全角色
|
1
|
mvn tomcat6:roles
|
构建一个可执行的 War/Jar
版本 2.0 开始,嵌入的 Apache Tomcat7 可以构建一个可执行的 War/Jar(只支持 tomcat7 插件)
注意:项目必须有 pom 或者 war 的打包信息
添加到您的 war 模块:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
...
war or pom
...
...
...
org.apache.tomcat.maven
tomcat7-maven-plugin
2.3
-SNAPSHOT
tomcat-run
exec-war-only
package
foo
src/main/tomcatconf/server.xml
default
value is exec-war but you can customize
default
value is jar
...
...
...
|
添加到 pom 模块
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
...
war
...
...
...
org.apache.tomcat.maven
tomcat7-maven-plugin
2.3
-SNAPSHOT
tomcat-run
exec-war-only
package
a groupId
and artifactId
version
war
/
true
org.apache.derby
derby
10.1
.
3.1
javax.mail
mail
1.4
...
...
...
|
生成可执行的 War/Jar
在上面配置下,执行
|
1
|
java -jar yourjar
|
下面是使用帮助
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
usage: java -jar [path to your exec war jar]
-ajpPort ajp port to use
-clientAuth enable client authentication
for
https
-D key=value
-extractDirectory path to extract war content,
default
value: .extract
-h,--help help
-httpPort http port to use
-httpProtocol http protocol to use: HTTP/
1.1
or
org.apache.coyote.http11.Http11Nio
Protocol
-httpsPort https port to use
-maxPostSize max post size in bytes to use
-keyAlias alias from keystore
for
ssl
-loggerName logger to use: slf4j to use slf4j
bridge on top of jul
-obfuscate obfuscate the password and exit
-resetExtract clean previous extract directory
-serverXmlPath server.xml to use, optional
-X,--debug debug
|
已知限制
一些 goal 不在 tomcat7 mojo。 这些在 tomcat6 mojo 中的 container goal,需要修改你的 manager url :
使用 http://localhost:8080/manager/text 替换默认的 tomcat6 url
- http://tomcat.apache.org/maven-plugin.html
