tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Thread.currentThread().getContextClassLoader() in Tomcat 3.2
Date Wed, 22 Nov 2000 07:32:16 GMT
"Roytman, Alex" wrote:

> I would like to use Thread.currentThread().getContextClassLoader() with
> Tomcat 3.2 to resolve one common problem when class from system classpath
> needs to call something loaded by tomcat context's loader. As far as I
> understand Tomcat 3.2 suppose to run under jdk1.1 so it does not do
> Thread.currentThread().setContextClassLoader() before it hands control to a
> Servlet.

If Tomcat 3.2 runs in a Java2 environment, it does in fact call
setContextClassLoader(), assigning the webapp class loader for the currently
selected web application to the current request thread.  Tomcat 4.0 does this
under all circumstances, because it requires a Java2 environment.  However, the
fact that this occurs has nothing to do with your issue.

Under any version of Tomcat, what you are asking for does not work.  More
importantly, it *should not* work.  Class loaders are only allowed to look *up*
the class loader hierarchy (and, of course, such a hierarchy exists only in a
Java2 environment).  Classes that are loaded from the system class path *do not*
have any access to classes loaded only by a webapp's class loader.  If they did,
it would violate the whole concept of a web application being self contained.

If you have a class that needs access to classes that are loaded from
WEB-INF/classes and WEB-INF/lib, that class itself must be loaded from one of
those two places (and therefore loaded by the webapp class loader).

Craig McClanahan

View raw message