tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: Thread.currentThread().setContextClassLoader() [was: ServletContext.getResourceAsStream() in 3.2?]
Date Wed, 13 Dec 2000 04:59:06 GMT


"Roytman, Alex" wrote:

> Tomcat developers, please correct me if I am wrong but as far as I know
> Tomcat 3.2 does not set ContextClassLoader for its threads.

The context class loader is a Java2 thing.  Since Tomcat 3.2 runs under JDK 1.1
as well, it cannot do this by default.  However, you can enable it by adding the
following in your server.xml file:

    <RequestInterceptor
     className="org.apache.tomcat.request.Jdk12Interceptor />

Note -- any web application that depends on this (setting the context class
loader) is ***not*** guaranteed to be portable, because it is ***not*** required
by the servlet specification.

> So you are using
> main class loader which knows nothing about your WEB-INF/lib

This is not true.

You are using a class loader that is aware of JAR files in WEB-INF/lib, and
unpacked classes in WEB-INF/classes, even on a JDK 1.1 system.  It just doesn't
call the Thread.setContextClassLoader() method by default.

>
> I had a different problem - when code loaded by main classloader need to
> load classes from WEB-INF/lib. I solved it by writing request and context
> interceptors for tomcat to call
> Thread.currentThread().setContextClassLoader() for each thread before it
> touches a servlet (doing init/destroy or serving request)
>

See above.

Craig McClanahan

PS:  Note that Tomcat 4.0, because it is guaranteed a Java2 platform as a
prerequisite, calls Thread.setContextClassLoader() on every request by default.



Mime
View raw message