简体   繁体   English

如何使用maven-tomcat7-plugin在Tomcat上适当地热部署/重新部署战争?

[英]How to properly hot deploy/redeploy war on Tomcat with maven-tomcat7-plugin?

I know there are many threads talking about it, but I expose a situation that I have not been able to solve with their help. 我知道有很多线程在谈论它,但是我暴露出一种情况,我无法在他们的帮助下解决。 I hope that my problem and if in the future it is solved I can help more people in my situation. 我希望我的问题以及将来的解决方案能够在我所处的环境中帮助更多的人。

I'm trying to do a hot deployment of a war in Tomcat and I find myself with the following four situations: 我正在尝试在Tomcat中进行战争的热部署,并且发现自己遇到以下四种情况:

Case 1 情况1

Deployment command executed from project folder: 从项目文件夹执行的部署命令:

mvn clean install org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy -P PROFILE_ONE,PROFILE_TWO -Dmaven.skip.test=true -DskipTests=true -Dmaven.javadoc.skip=true -Dsource.skip=true -Dproject.build.sourceEncoding=UTF-8 -Dcobertura.skip=true -Dmaven.skip.test=true -DskipTests=true -Dmaven.javadoc.skip=true -Dsource.skip=true -Dproject.reporting.outputEncoding=UTF-8 -Dmaven.tomcat.path=/MY_PATH -Dmaven.tomcat.url=http://localhost:8081/manager/text -Dmaven.tomcat.server=TomcatServer -Dtomcat.password=TOMCAT_USER -Dtomcat.username=TOMCAT_PASSWORD

AND apache-tomcat-7.0.91\\conf\\context.xml with the following properties: AND apache-tomcat-7.0.91 \\ conf \\ context.xml具有以下属性:

<Context antiResourceLocking="true" antiJARLocking="true">

Case 1 result 情况1结果

The deployment seems to work fine but when I enter the application the following error appears: 部署工作正常,但是当我进入应用程序时出现以下错误:

This page can not be found (localhost) No web page was found for the address http://localhost:8081/MY_PATH/#/PATH . 找不到此页面(localhost)找不到地址为http:// localhost:8081 / MY_PATH /#/ PATH的网页 HTTP ERROR 404 HTTP错误404

Case 2 情况二

Same command of case 1 executed from project folder and apache-tomcat-7.0.91\\conf\\context.xml without antilocking properties: 从项目文件夹和apache-tomcat-7.0.91 \\ conf \\ context.xml执行的情况1的相同命令,没有防锁定属性:

<Context>

Case 2 result 案例2结果

The deployment and the application work correctly, but when I try to do a redeploy, with the same command and adding the property -Dmaven.tomcat.update=true does not work correctly because there are several jars that are blocked and tomcat cannot delete them. 部署和应用程序正常运行,但是当我尝试重新部署时,使用相同的命令并添加属性-Dmaven.tomcat.update=true不能正常运行,因为有几个jar被阻止,并且tomcat无法删除它们。 (This is the reason why in other cases I add antilocking properties) (这就是为什么在其他情况下我添加防锁定属性的原因)

Case 3 情况3

Same command of case 1 executed from project folder and apache-tomcat-7.0.91\\conf\\context.xml with the following properties: 从项目文件夹和apache-tomcat-7.0.91 \\ conf \\ context.xml执行的情况1的相同命令具有以下属性:

<Context antiJARLocking="true">

Case 3 result 情况3结果

Equal to the result of case 2. 等于案例2的结果。

Case 4 案例4

Same command of case 1 executed from project folder and apache-tomcat-7.0.91\\conf\\context.xml with the following properties: 从项目文件夹和apache-tomcat-7.0.91 \\ conf \\ context.xml执行的情况1的相同命令具有以下属性:

<Context antiResourceLocking="true">

Case 4 result 案例4结果

Equal to the result of case 1. 等于情况1的结果。

end of cases 案件结束

As you can see, my goal is to do a first deployment and then redeploy the same application (with changes in project folder). 如您所见,我的目标是先进行部署,然后重新部署相同的应用程序(在项目文件夹中进行更改)。 All the information I have found talks about the antilocking properties, but as I said above, when I put them on context.xml, the application it seems not to work. 我找到的所有信息都在讨论防锁定属性,但是正如我上面所说,当我将它们放在context.xml上时,该应用程序似乎无法正常工作。 It is important to say that due to project needs I cannot change the name of the war. 重要的是要说,由于项目需要,我无法更改战争的名称。

EDIT 1 编辑1

Case 5 案例5

I have also tried with the following command: 我也尝试使用以下命令:

mvn clean install -U -P PROFILE_ONE,PROFILE_TWO -Dmaven.skip.test=true -DskipTests=true -Dmaven.javadoc.skip=true -Dsource.skip=true -Dproject.build.sourceEncoding=UTF-8 -Dcobertura.skip=true -Dmaven.skip.test=true -DskipTests=true -Dmaven.javadoc.skip=true -Dsource.skip=true -Dproject.reporting.outputEncoding=UTF-8 org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:redeploy-only -Dmaven.tomcat.path=/MY_PATH -Dmaven.tomcat.url=http://localhost:8081/manager/text -Dmaven.tomcat.server=TomcatServer -Dtomcat.password=admin -Dtomcat.username=admin

And apache-tomcat-7.0.91\\conf\\context.xml with the following properties: apache-tomcat-7.0.91 \\ conf \\ context.xml具有以下属性:

<Context antiResourceLocking="true">

Case 5 Result KO 个案5结果KO

Equal to the result of case 1. 等于情况1的结果。

Why antiResourceLocking="true" causes result 1 error? 为什么antiResourceLocking="true"导致结果1错误?

You shouldn't use both antiResourceLocking and antiJARLocking features according to Tomcat : 根据Tomcat,您不应该同时使用antiResourceLockingantiJARLocking功能:

antiJARLocking is a subset of antiResourceLocking and therefore, to prevent duplicate work and possible issues, only one of these attributes should be set to true at any one time. antiJARLocking是antiResourceLocking的子集,因此,为防止重复工作和可能出现的问题,任何时候都应仅将这些属性之一设置为true。

There also specific warnings about using antiResourceLocking 还有关于使用antiResourceLocking的特定警告

Please note that setting this to true has some side effects, including the disabling of JSP reloading in a running server: see Bugzilla 37668. 请注意,将此设置为true有一些副作用,包括在运行的服务器中禁用JSP重载:请参见Bugzilla 37668。

Please note that setting this flag to true in applications that are outside the appBase for the Host (the webapps directory by default) will cause the application to be deleted on Tomcat shutdown. 请注意,在主机的appBase之外的应用程序(默认为webapps目录)中将此标志设置为true会导致在Tomcat关闭时删除该应用程序。 You probably don't want to do this, so think twice before setting antiResourceLocking=true on a webapp that's outside the appBase for its Host. 您可能不想这样做,因此,在主机的appBase之外的Web应用程序上设置antiResourceLocking = true之前,请三思。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM