Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a custom tomcat session manager without putting the jar in the CATALINA_HOME directory?

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.

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.

like image 418
user439407 Avatar asked Jun 07 '12 02:06

user439407


Video Answer


1 Answers

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.

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.

EDIT 2015-067-01

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

like image 109
Christopher Schultz Avatar answered Sep 30 '22 12:09

Christopher Schultz