You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Craig R. McClanahan" <Cr...@eng.sun.com> on 2000/12/13 05:59:06 UTC

Re: Thread.currentThread().setContextClassLoader() [was: ServletContext.getResourceAsStream() in 3.2?]


"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.



Complete Installation steps ..

Posted by Sunil Kumar K <su...@majoris.com>.
Hi Guys,

    Can u ppl help me out....
    can anyone send me a complete installation script for tomcat 4 on Red
Hat Linux 6.2
    I have apache 1.3.14
    apache Jserv 1.1.2

cheers
Sunil


----- Original Message -----
From: "Craig R. McClanahan" <Cr...@eng.sun.com>
To: <to...@jakarta.apache.org>
Sent: Wednesday, December 13, 2000 10:29 AM
Subject: Re: Thread.currentThread().setContextClassLoader() [was:
ServletContext.getResourceAsStream() in 3.2?]


>
>
> "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.
>
>