maven配置cargo实现远程部署项目到tomcat

网上看很很多篇文章,都没有实现,还是费了很大的劲了,有必要总结一下

1.给tomcat添加manager权限,在conf下的tomcat-users.xml中的<tomcat-users>添加

  1. <role rolename="manager-gui"/>
  2. <role rolename="manager-script"/>
  3. <role rolename="admin"/>
  4. <role rolename="admin-gui"/>
  5. <user username="tomcat" password="tomcat" roles="manager-gui,manager-script,admin,admin-gui"/>

验证是否添加成功:

125456_E4nq_2913509.png

 需要输入用户名和密码,这个时候输入设置的用户名和密码,正常则进入,没有权限则报403,检查上面的配置。还有一个需要注意的情况是tomcat8可能需要在这里去掉一点东西。

打开webapps下的host-manager和manager,都有一个共同的文件夹META-INF,里面都有context.xml 需要配置 context.xml。

把 <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> 去掉即可。因为这里限制了 只有本地才可以访问。

2.修改tomcat的项目路径,配置文件在conf下,如下

  1. <Context docBase="H:\apache-tomcat-7.0.73-web\webapps\taotaoweb" path="/" debug="0" reloadable="true"/>

这里的docbase是项目的路径。reloadable是在修改jsp页面的时候,不需要重启自动加载。path配置是指在根路径。

 

 2.在maven中添加配置

  1. <build>
  2. <finalName>taotaoweb</finalName>
  3. <!-- directory缺省情况下指向target -->
  4. <!--<directory>${basedir}/target</directory>-->
  5. <plugins>
  6. <!-- 配置Tomcat插件 -->
  7. <plugin>
  8. <groupId>org.apache.tomcat.maven</groupId>
  9. <artifactId>tomcat7-maven-plugin</artifactId>
  10. <configuration>
  11. <port>8081</port>
  12. <path>/</path>
  13. </configuration>
  14. </plugin>
  15.  
  16. <!-- mvn cargo:redeploy -->
  17. <plugin>
  18. <groupId>org.codehaus.cargo</groupId>
  19. <artifactId>cargo-maven2-plugin</artifactId>
  20. <configuration>
  21. <wait>true</wait>
  22. <container>
  23. <containerId>tomcat7x</containerId><!-- 这个是固定的,如果是tomcat7就这样配置 -->
  24. <type>remote</type><!-- 远程部署类型必须是remote -->
  25. </container>
  26. <configuration>
  27. <type>runtime</type><!-- 如果你在容器属性中指定类型为"remote"的话,那么你必须在如下配置type==runtime -->
  28. <properties><!-- 这里的是uri,并且,配置固定 -->
  29. <cargo.remote.uri>http://127.0.0.1:8081/manager/text</cargo.remote.uri>
  30. <cargo.remote.username>tomcat</cargo.remote.username><!-- tomcat配置的manager的用户名和密码 -->
  31. <cargo.remote.password>tomcat</cargo.remote.password>
  32. <update>true</update><!-- 一定要配置<update>true</update>,不然会报错。 -->
  33. <!-- <path>/${project.build.finalName}</path> -->
  34. <!-- war文件路径缺省情况下指向target 这里的配置和最上面的fileName效果一样。-->
  35. <!-- <warFile>${basedir}/target/${project.build.finalName}.war</warFile>-->
  36. </properties>
  37. </configuration>
  38. <deployables>
  39. <deployable>
  40. <groupId>com.taotao</groupId><!-- 这两个可以配置成占位符的形式 -->
  41. <artifactId>taotao-manager-web</artifactId>
  42. <type>war</type><!-- 打成war包 -->
  43. <properties>
  44. <context>/taotaoweb</context><!--项目部署后文件夹名字 -->
  45. </properties>
  46. </deployable>
  47. </deployables>
  48. </configuration>
  49. </plugin>
  50. <!-- Test 编译跳过测试-->
  51. <plugin>
  52. <groupId>org.apache.maven.plugins</groupId>
  53. <artifactId>maven-surefire-plugin</artifactId>
  54. <configuration>
  55. <skipTests>true</skipTests><!-- 跳过测试 -->
  56. </configuration>
  57. </plugin>
  58. <!-- War 打包配置包名-->
  59. <plugin>
  60. <groupId>org.apache.maven.plugins</groupId>
  61. <artifactId>maven-war-plugin</artifactId>
  62. <configuration>
  63. <warName>taotaoweb</warName>
  64. <failOnMissingWebXml>false</failOnMissingWebXml><!-- 使用maven创建项目时有时在pom.xml的war处出现failOnMissingWebXml的错误 -->
  65. </configuration>
  66. </plugin>
  67. </plugins>
  68. </build>

如果想抽取出来一些配置文件,就可以使用占位符的形式,这样的话,方便修改。

在项目的根目录下执行一下三个命令

  1. mvn clean compile
  2. mvn clean package
  3. mvn cargo:redeploy

查看结果。

注意:这里会有一个问题。就是每次部署项目,tomcat就会内存泄露一次,多了以后就会内存溢出而停止工作

解决方法:

一,部署多次以后,重启一次tomcat

二,参考http://www.cnblogs.com/xyb930826/p/5725340.html

转载于:https://my.oschina.net/luleilei516/blog/825441

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值