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

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

问题描述

可以在 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:热部署新的 jars的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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