How to dynamically update (hot swap) jars in a web-app?

Jus12 picture Jus12 · Feb 27, 2013 · Viewed 7.7k times · Source

I have a webapp in a war archive which is deployed on cloudfoundry. One of the libraries ("somelib.jar") used by the app is made by another developer.

I would like a way for him to upload several different versions of somelib.jar and test the behaviour of the app. I have managed to get the jar uploaded to WEB-INF/lib directory of the deployment. I have also managed to unpack the jar into WEB-INF/classes. However, I have not managed to get the new version of the jar to be used. I tried various hacks such as those described in this question and this question without any luck.

Everytime, the classes/jars that get loaded the first time get used after that, even if we replace the actual .class or .jar file in the above directories.

Is there any easy way to achieve what I want?

Note: Since I dont have control of Tomcat (where it runs), I cannot configure Tomcat or make any changes to the server. I just have control on my war file, so everything needs to be done programmatically.

EDIT: the reason I want this is to reduce our testing time. Currently someone gives me a new version of somelib.jar, I repackage it into my application, upload to CF, send him a notification, then he tests the behavior of the new jar. What I would have preferred is that he upload his jar directly to CF and do the testing whenever he has a new version without the unnecessary intermediate delay.

Answer

srini.venigalla picture srini.venigalla · Feb 27, 2013

In tomcat 7, you can version your WAR file and the new versions will gradually kick in.

http://www.tomcatexpert.com/blog/2011/05/31/parallel-deployment-tomcat-7