创建自定义 tomcat 会话管理器而不将 jar 放在 CATALINA_HOME 目录中? [英] Creating a custom tomcat session manager without putting the jar in the CATALINA_HOME directory?

查看:42
本文介绍了创建自定义 tomcat 会话管理器而不将 jar 放在 CATALINA_HOME 目录中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Tomcat 开发一个自定义会话管理器,我得到了一个警告,我必须将 jar(和所有相关的 jar)放在 CATALINA_HOME/lib 目录中,否则我会得到一个 noclassdef found 异常,即使尽管这些类位于 WEB-INF/lib 目录中.

I am working on a custom session manager for Tomcat and I got it working with one caveat, I have to put the jar(and all the associated jars) in the CATALINA_HOME/lib directory or I get a noclassdef found exception, even though the classes are in the WEB-INF/lib directory.

有没有办法强制tomcat在加载会话管理器时查看Web应用程序li​​b目录?将它放在 lib 目录中很容易出错(因为您必须记住在升级和/或在新系统上安装时复制 jar)并使 jar 的开发更加困难.

Is there any way to force tomcat to look in the web apps lib directory when it is loading a session manager? Putting it in the lib directory is error-prone(as you have to remember to copy the jar over when upgrading and/or installing on a new system) and makes development of the jar more difficult.

推荐答案

从 Tomcat 7.0.27 开始,META-INF/context.xml 文件中的元素由 commons-digester 处理,有效的 ClassLoader 被设置为加载 ContextConfig 类的那个——一个牢牢驻留在 Tomcat 的服务器 ClassLoader 中的位于任何可以访问 Web 应用程序类的 ClassLoading 链之外.

As of Tomcat 7.0.27, the <Manager> element in your META-INF/context.xml file is processed by the commons-digester and the effective ClassLoader is set to that which loaded the ContextConfig class -- one which firmly resides in Tomcat's server ClassLoader, which is outside of the ClassLoading chain of anything with access to the webapp's classes.

因此,如果不修改 Tomcat 源代码,将无法从您的 web 应用程序中加载您的 Manager.考虑加入 Tomcat 用户的邮件列表来讨论这样的功能.

So, without modifying the Tomcat source, there will be no way to load your Manager from within your webapp. Consider joining the Tomcat users' mailing list to discuss such a feature.

编辑 2015-067-01

如果您想为您的 Web 应用程序指定一个 ClassLoader,您需要在 中使用 元素.: http://tomcat.apache.org/tomcat-8.0-doc/config/loader.html

If you want to specify a ClassLoader for your web application, you'll need to use the <Loader> element within your <Context>: http://tomcat.apache.org/tomcat-8.0-doc/config/loader.html

这篇关于创建自定义 tomcat 会话管理器而不将 jar 放在 CATALINA_HOME 目录中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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