On Thu, 15 Mar 2001, Andrew Gilbert wrote:

> Carlos,
> 
> Thanks. This is interesting. Can you explain what the effect of
> Thread.setContextClassLoader() is? Does it make classes from the
> WEB-INF/lib and WEB-INF/classes area avaiable to classes loaded by 
> the boot class or system class loader?
> 

You can make them visible, but the class from the boot classloader or
system classloader has to know what to do -- it calls
Thread.getContextClassLoader() to get the class loader for the current
thread, and asks *that* classloader to create the new object, instead of
using the "new" operator.

WARNING:  Thread.setContextClassLoader() does not exist in JDK 1.1 (which
Tomcat 3.x is designed to support), so this change can only be added to
optional Tomcat components that are loaded only when running in a Java2
environment.

WARNING:  Tomcat 4.0 (which requires Java2 already) does use the context
class loader in this manner already.  However, this behavior is *not* in
the servlet specification, and you can *not* rely on it if your
application needs to be portable.  (For that matter, servlet containers
are not even required to provide a "shared JAR files" mechanism -- they
are only required to support WEB-INF/classes and WEB-INF/lib.)

> Andrew
> 

Craig McClanahan

Reply via email to