hcohen
hcohen

Reputation: 325

Change part of Java class code after deploying to server as webapp

I have a Java servlet web app (.war) which I deployed to Tomcat Ubuntu server.

Can I change the content the Java classes at: myProject/WEB-INF/classes/
without re-export-and-deploy the entire app ?

Thanks in advance.

Upvotes: 4

Views: 5395

Answers (2)

Miljen Mikic
Miljen Mikic

Reputation: 15241

Disclaimer: I don't recommend doing this because it can give unexpected results. I am aware that sometimes you need to do "quick-and-dirty" fix, but consider yourself warned :)

I assume you have a Web application, let's call it 'MyApp'. Go to <TOMCAT-DIR>/webapps and locate your MyApp.war file. Put new .class file into the MyApp.war (open it with some archiver) and then delete the folder <TOMCAT-DIR>/webapps/MyApp. Deleting the folder means undeployment for Tomcat. After some time, Tomcat will figure out that it has a .war file in his <TOMCAT-DIR>/webapps folder that needs to deploy and it will automatically do it. You will see in Tomcat's log something like:

Aug 25, 2015 9:24:55 AM org.apache.catalina.startup.HostConfig undeploy
INFO: Undeploying context [/MyApp]
Aug 25, 2015 9:24:55 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /home/tomcat/apache-tomcat-7.0.55/webapps/MyApp.war
Aug 25, 2015 9:25:17 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /home/tomcat/apache-tomcat-7.0.55/webapps/MyApp.war has finished in 21,937 ms

And there you go, you just refreshed your application without redeployment and without restarting server.

Upvotes: 2

Nitesh Virani
Nitesh Virani

Reputation: 1712

I could thought of below to re deploy your app without restarting tomcat:

  1. Modify your java file
  2. Generate .class file
  3. Replace it with your existing file in Tomcat
  4. Trigger your app restart by touching WEB-INF/web.xml

Upvotes: 7

Related Questions