Is it possible to hot swap a single class manually with Tomcat?

1

Is it possible to reload a single class manually with Tomcat 8 without having to restart the server? This is for a production environment that I'm talking about, so I don't want to use the reloadable attribute to achieve this. I just occasionally might have an update to a single class (or couple of classes) that I'd like tomcat to recognize.

Since it is possible to do this with the reloadable attribute, or setting watched resources, I was hoping it's also possible to trigger manually somehow.

RTF

Posted 2015-11-03T12:36:55.140

Reputation: 326

Answers

1

If you replace the class file and Tomcat has already loaded that class you will need to trigger a redploy of the web application for the updated class to be picked up. The simplest way to trigger this is to touch the context.xml file of the web application. If it doesn't have one there are some other options. See this list in the Tomcat docs: http://tomcat.apache.org/tomcat-8.0-doc/config/automatic-deployment.html#Modified_files

Mark Thomas

Posted 2015-11-03T12:36:55.140

Reputation: 136

I tried touching my web.xml on a development server, but there was no reload. I also tried adding something new to the web.xml and saving it, but still no reload. Are you sure about that tip? – RTF – 2015-11-03T18:36:49.837

Sorry. You need redploy. I've updated my answer. – Mark Thomas – 2015-11-03T18:40:23.037

For the record, reload is effectively stop followed by start whereas redploy is equivalent to removing the web app and adding a new one. Some requests may get lost if they arrive in the middle of the redeploy. – Mark Thomas – 2015-11-03T18:41:36.383

Thanks for the help, but I decided to go with the Tomcat Manager instead – RTF – 2015-11-06T13:11:27.060

0

In the end I decided to go with the Tomcat Manager. I'm using themanager-script functionality of the manager (GUI etc. is disabled) and I'm limiting access to localhost only. I've wrapped a reload command in a small shell script, like this:

#!/bin/bash
echo Reloading application now...
curl http://my-user:my-password@localhost:8080/manager/text/reload?path=/
echo Done.

That reloads the entire webapp, which I guess is fine for me.

RTF

Posted 2015-11-03T12:36:55.140

Reputation: 326