您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页maven 插件系列1 :tomcat插件 集成

maven 插件系列1 :tomcat插件 集成

来源:二三四教育网
Paste_Image.png
命令
1.本地运行(tomcat7:run)
pom.xml文件配置
<!-- 本地环境使用 -->
<plugin>   
  <groupId>org.apache.tomcat.maven</groupId>   
  <artifactId>tomcat7-maven-plugin</artifactId>   
  <version>2.1</version>   
  <configuration>      
    <hostName>localhost</hostName>    <!--   Default: localhost -->  
    <port>8080</port>    <!-- 启动端口 Default:8080 --> 
    <path>/api</path>    <!-- 访问应用路径  Default: /${project.artifactId}-->  
    <uriEncoding>UTF-8</uriEncoding>      <!-- uri编码 Default: ISO-8859-1 -->
  </configuration>
</plugin>
2.远程部署(tomcat7:deploy)
2.1 pom.xml配置
<!-- 本地环境使用 -->
<plugin>    
  <groupId>org.apache.tomcat.maven</groupId>    
  <artifactId>tomcat7-maven-plugin</artifactId>    
  <configuration>        
    <url>http://192.168.1.110:8080/manager/text</url>        
    <server>tomcat</server>        
    <username>xxxx</username>        
    <password>xxxxx</password>        
    <path>/api</path>   
 </configuration>
</plugin>
2.2 其他配置

2.2.1 .在tomcat中配置用户权限(用户名密码自行修改:本例是 tomcat,tomcat)
我们需要实现热部署,自然就需要通过maven操作tomcat,所以就需要maven取得操作tomcat的权限。
在tomcat的安装目录下,修改conf / tomcat-user.xml文件,在<tomcat-users> 节点下面增加如下配置:

<role rolename="manager-gui" />
<role rolename="manager-script" />
<user username="tomcat" password="tomcat" roles="manager-gui, manager-script" />

2.2.2 在maven中添加server,配置tomcat的管理员帐号密码
maven要操作tomcat,那么maven就要拿到tomcat的管理员帐号和密码才能够使用.
设置maven配置的setting.xml文件.在<server> 节点下面增加如下配置:

<server> 
  <id>admin</id> 
  <username>tomcat</username> 
  <password>tomcat</password> 
</server>
2.3 注意事项
  • 部署之前应先启动tomcat服务器,否则报Connection refused错误
    错误信息:[ERROR]Failed to execute goal org.apache.tomcat.maven: tomcat7-maven-plugin: 2.0- SNAPSHOT: deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Connection refused: connect -> [Help 1]
  • 第一次部署使用tomcat7:deploy 以后使用tomcat7:redeploy
3.显示帮助信息(tomcat7:help)
This plugin has 14 goals:

tomcat7:deploy
  Deploy a WAR to Tomcat.

tomcat7:deploy-only
  Deploy a WAR to Tomcat without forking the package lifecycle.

tomcat7:exec-war
  Create a self executable jar file containing all necessary Apache Tomcat
  classes. This allows for using just java -jar mywebapp.jar to run your webapp
  without needing to install a Tomcat instance. More details here.

tomcat7:exec-war-only
  Same as exec-war goal without forking the package lifecycle.

tomcat7:help
  Display help information on tomcat7-maven-plugin.
  Call mvn tomcat7:help -Ddetail=true -Dgoal=<goal-name> to display parameter
  details.

tomcat7:redeploy
  Redeploy a WAR in Tomcat. (Alias for the deploy goal with its update parameter
  set to true.)

tomcat7:redeploy-only
  Redeploy a WAR in Tomcat without forking the package lifecycle. (Alias for the
  deploy-only goal with its update parameter set to true.)

tomcat7:run
  Runs the current project as a dynamic web application using an embedded Tomcat
  server.

tomcat7:run-war
  Runs the current project as a packaged web application using an embedded
  Tomcat server.

tomcat7:run-war-only
  Same as run-war goal without forking the package cycle.

tomcat7:shutdown
  Shuts down all possibly started embedded Tomcat servers. This will be
  automatically done through a shutdown hook or you may call this Mojo to shut
  them down explictly.
  
  By default the shutdown goal is not bound to any phase. For integration tests
  you might want to bind it to post-integration-test.

tomcat7:standalone-war
  This Mojo will create an executable war file with embedded Tomcat that is also
  capable of being deployed elsewhere.

tomcat7:standalone-war-only
  This Mojo will create an executable war file with embedded Tomcat that is also
  capable of being deployed elsewhere.

tomcat7:undeploy
  Undeploy a WAR from Tomcat.

Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务