Tomcat doesn't provide any mechanism to reload a single JAR. However, the whole context can be reloaded.
You just need to tell Tomcat to watch for your JAR in context.xml, like this,
<?xml version="1.0" encoding="UTF-8"?>
<Context override="true" swallowOutput="true" useNaming="false">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/lib/your.jar</WatchedResource>
<Manager pathname=""/>
</Context>
We do this on production. Tomcat used to have some memory leaks but we haven't found any issues with Tomcat 5.5 or later.
Don't know if it's still necessary. We have to make following calls to avoid memory leak during hot deployment.
public void contextDestroyed(ServletContextEvent sce) {
// To fix the known memory leaks during re-deploy
ClassLoader contextClassLoader =
Thread.currentThread().getContextClassLoader();
LogFactory.release(contextClassLoader);
java.beans.Introspector.flushCaches();
...
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…