Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

java - Tomcat: hot deploying new jars

Can you hot deploy JAR files on Tomcat 5? The idea is to avoid restarting Tomcat and still be able to load (via reflection) some class from a newly added JAR. Can it be done? How? Is it unadvisable for a production system? Thanks

Edit: my scenario requires the addition of new JAR files for which the names aren't known in advance. Can the server be "watching" a directory of JARs rather than specific JARs?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();
        ...
   }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...