简体   繁体   中英

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:

Case 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:

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

Case 1 result

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 . HTTP ERROR 404

Case 2

Same command of case 1 executed from project folder and apache-tomcat-7.0.91\\conf\\context.xml without antilocking properties:

<Context>

Case 2 result

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. (This is the reason why in other cases I add antilocking properties)

Case 3

Same command of case 1 executed from project folder and apache-tomcat-7.0.91\\conf\\context.xml with the following properties:

<Context antiJARLocking="true">

Case 3 result

Equal to the result of case 2.

Case 4

Same command of case 1 executed from project folder and apache-tomcat-7.0.91\\conf\\context.xml with the following properties:

<Context antiResourceLocking="true">

Case 4 result

Equal to the result of case 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. It is important to say that due to project needs I cannot change the name of the war.

EDIT 1

Case 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:

<Context antiResourceLocking="true">

Case 5 Result KO

Equal to the result of case 1.

Why antiResourceLocking="true" causes result 1 error?

You shouldn't use both antiResourceLocking and antiJARLocking features according to Tomcat :

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.

There also specific warnings about using 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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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