Tomcat:热部署新的jar [英] Tomcat: hot deploying new jars

查看:598
本文介绍了Tomcat:热部署新的jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以在Tomcat 5上热部署JAR文件吗?我们的想法是避免重新启动Tomcat,并且仍然可以从新添加的JAR中加载(通过反射)某些类。
能做到吗?怎么样?生产系统是不可取的?
谢谢

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

编辑:我的方案需要添加新的JAR文件,这些文件的名称事先是未知的。服务器可以观察JAR目录而不是特定JAR吗?

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?

推荐答案

Tomcat不提供任何重新加载机制一个JAR。但是,可以重新加载整个上下文。

Tomcat doesn't provide any mechanism to reload a single JAR. However, the whole context can be reloaded.

你只需告诉Tomcat在context.xml中监视你的JAR,就像这样,

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>

我们在生产时这样做。 Tomcat曾经有过一些内存泄漏,但是我们没有发现Tomcat 5.5或更高版本的任何问题。

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

这篇关于Tomcat:热部署新的jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆