Tomcat Maven Plugin使用

Easter79
• 阅读 555

原文同步至:http://www.waylau.com/tomcat-maven-plugin/

Apache Tomcat 的 Maven 插件提供了 goal,实现将 Apache Tomcat servlet 容器整合进 WAR 项目。你可以通过 Apache Maven 运行 WAR 项目而无需部署 WAR 文件到 Apache Tomcat 的实例。

详见下面网站:

##源码:

svn 路径:

http://svn.apache.org/repos/asf/tomcat/maven-plugin/trunk/

##功能:

  • 支持 Apache Tomcat7
  • 构建一个可执行的 War/Jar

##使用

自从版本 2.0-beta-1以后, tomcat mojos 更名为 tomcat6 和 tomcat7,使用配置如下:

<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat6-maven-plugin</artifactId>
      <version>2.3-SNAPSHOT</version>
    </plugin>
    <plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat7-maven-plugin</artifactId>
      <version>2.3-SNAPSHOT</version>
    </plugin>
  </plugins>
</pluginManagement>

或者添加 groupId 到你的 settings.xm

 <pluginGroups>
    ....
    <pluginGroup>org.apache.tomcat.maven</pluginGroup>
    ....
 </pluginGroups>

###在 tomcat 发布不显示项目名称

配置如下

<plugin>
  <groupId>org.apache.tomcat.maven</groupId>
  <artifactId>tomcat7-maven-plugin</artifactId>
  <version>2.2</version>
    <configuration>
    <path>/</path>
    </configuration>
</plugin>

##Context Goals

###部署 WAR 项目

在 tomcat:deploy 部署后,再次部署 WAR 执行:

mvn package tomcat6/7:redeploy

在执行 tomcat:exploded 后,再次部署 WAR 执行:

mvn war:exploded tomcat6/7:redeploy

在执行 tomcat:inplace 后,再次部署 WAR 执行:

mvn war:inplace tomcat6/7:redeploy

在执行 tomcat:deploy 后,再次部署 context.xml 文件执行:

mvn tomcat6/7:redeploy

注意: context.xml指定 docBase后 ,还需要像上面那样调用 war:exploded或者war:inplace

###移除部署 WAR 项目

mvn tomcat6/7:undeploy

###启动 WAR 项目

mvn tomcat6:start

###停止 WAR 项目

mvn tomcat6:stop

###列出会话统计表

mvn tomcat6:sessions

##Container Goals

###列出部署的应用s

mvn tomcat6:list

###列出服务器信息

mvn tomcat6:info

###列出 JNDI 资源

列出 Tomcat 版本, 操作系统, 和 JVM 等信息

mvn tomcat6:resources

另外,列出特定类型你可以只输入 JNDI 资源类型:

mvn -Dmaven.tomcat.type=my.class.name tomcat6:resources

###列出安全角色

mvn tomcat6:roles

##构建一个可执行的 War/Jar

版本 2.0 开始,嵌入的 Apache Tomcat7 可以构建一个可执行的 War/Jar(只支持 tomcat7 插件)

注意:项目必须有 pom 或者 war 的打包信息

###添加到您的 war 模块:

<project>
  ...
  <packaging>war or pom</packaging>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.3-SNAPSHOT</version>
        <executions>
          <execution>
            <id>tomcat-run</id>
            <goals>
              <goal>exec-war-only</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <path>foo</path>
              <!-- optional, needed only if you want to use a preconfigured server.xml file -->
              <serverXml>src/main/tomcatconf/server.xml</serverXml>
              <!-- optional values which can be configurable -->
              <attachArtifactClassifier>default value is exec-war but you can customize</attachArtifactClassifier>
              <attachArtifactClassifierType>default value is jar</attachArtifactClassifierType>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

###添加到 pom 模块

<project>
  ...
  <packaging>war</packaging>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.3-SNAPSHOT</version>
        <executions>
          <execution>
            <id>tomcat-run</id>
            <goals>
              <goal>exec-war-only</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <!-- optional only if you want to use a preconfigured server.xml file -->
              <!--
              <serverXml>src/main/tomcatconf/server.xml</serverXml>
              -->
              <warRunDependencies>
                <warRunDependency>
                  <dependency>
                    <groupId>a groupId</groupId>
                    <artifactId>and artifactId</artifactId>
                    <version>version</version>
                    <type>war</type>
                  </dependency>
                  <contextPath>/</contextPath>
                </warRunDependency>
              </warRunDependencies>
              <!-- naming is disabled by default so use true to enable it -->
              <enableNaming>true</enableNaming>
              <!-- extra dependencies to add jdbc driver, mail jars, etc. -->
              <extraDependencies>
                <extraDependency>
                  <groupId>org.apache.derby</groupId>
                  <artifactId>derby</artifactId>
                  <version>10.1.3.1</version>
                </extraDependency>
                <extraDependency>
                  <groupId>javax.mail</groupId>
                  <artifactId>mail</artifactId>
                  <version>1.4</version>
                </extraDependency>
              </extraDependencies>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

###生成可执行的 War/Jar

在上面配置下,执行

java -jar yourjar

下面是使用帮助

usage: java -jar [path to your exec war jar]
 -ajpPort <ajpPort>                     ajp port to use
 -clientAuth                            enable client authentication for
                                        https
 -D <arg>                               key=value
 -extractDirectory <extractDirectory>   path to extract war content,
                                        default value: .extract
 -h,--help                              help
 -httpPort <httpPort>                   http port to use
 -httpProtocol <httpProtocol>           http protocol to use: HTTP/1.1 or
                                        org.apache.coyote.http11.Http11Nio
                                        Protocol
 -httpsPort <httpsPort>                 https port to use
 -maxPostSize <maxPostSize>             max post size in bytes to use
 -keyAlias <keyAlias>                   alias from keystore for ssl
 -loggerName <loggerName>               logger to use: slf4j to use slf4j
                                        bridge on top of jul
 -obfuscate <password>                  obfuscate the password and exit
 -resetExtract                          clean previous extract directory
 -serverXmlPath <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

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
2星期前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Wesley13 Wesley13
2年前
P2P技术揭秘.P2P网络技术原理与典型系统开发
Modular.Java(2009.06)\.Craig.Walls.文字版.pdf:http://www.t00y.com/file/59501950(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.t00y.com%2Ffile%2F59501950)\More.E
Stella981 Stella981
2年前
Netty 实现聊天功能
原文同步至http://www.waylau.com/nettychat/(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.waylau.com%2Fnettychat%2F)Netty(https://www.oschina.net/action/GoToLink?
Wesley13 Wesley13
2年前
Uber基于RNN的极端事件预测,解决交通问题
时间 2017061212:00:15  亿欧网(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.tuicool.com%2Fsites%2FAJj2Un)_原文_  http://www.iyiou.com/p/47628(https://www.oschina.n
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
6个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k