Concerning the use of the ClassLoader in Digester,
instead of using Digester.setContextClassLoader(boolean)
to determine whether or not to use the context CL in
the current thread, I proprose that there is a method
Digester.setClassLoader(ClassLoader). If it is set
to null, the Digester will just use the default
CL (i.e. the CL that loader the Digester). I'll submit
a patch for that behavior unless I hear otherwise. This
means that in order to use a web-app CL, that it must
be explicitly set by the developer. Such an API is
a little more robust (considering the various servlet
specs [2.2/2.3] and the various servlet container
implementations) and provides a little more flexibility
(in case you want a CL other than the default or web-app).
- Gidado
> -----Original Message-----
> From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 01, 2001 3:41 PM
> To: '[EMAIL PROTECTED]'
> Subject: Re: ClassLoaders (was: Difficulties with
> Commons-Digester 1.0)
>
>
>
>
> On Wed, 1 Aug 2001, Immanuel, Gidado-Yisa wrote:
>
> > I found a little time to increase my "expertise" on classloaders.
> > I created a little test jsp to see what types of ClassLoaders (CL)
> > are returned from the Thread.currentThread.contextClassLoader()
> > as well as the CLs that are used to load up classes in
> servlets/jsps.
> >
> > These are the results (I was going to include some
> non-Tomcat servers,
> > but did not get a chance).
> >
> > ServletContainer ContextClassLoader returns
> > --------------------------------------------------
> > Tomcat
> > 3.1.1 web-app CL
> > 3.2.3 system CL
> > 3.3-b1 "dependency-wrapped" system CL (?)
> > 4.0-b6 web-app CL
> >
> > What I'm seeing is that the contextClassLoader() method basically
> > returns a "system" ClassLoader for Tomcat 3.2.3 and 3.3-b1, whereas
> > 3.1.1 and 4.0-b6 return web-app CL. So it does not look like
> > one can safely rely on "contextClassLoader()" for getting the
> > "context" CL for applications deployed in a server environment.
> >
> > Are these results what you would expect?
> >
>
> For servlet 2.3 (and later) containers, you *will* be able to count on
> this. It'll be part of the J2EE 1.3 platform spec
> requirements that the
> container set the context class loader to something that can
> be used to
> load application classes -- for servlet/JSP, that means the
> webapp class
> loader. Prior to servlet 2.3, it's undefined and container dependent,
> although my understanding is that most containers do stick the webapp
> class loader here.
>
> > - Gidado
> >
>
> Craig
>
>
> >
> > p.s. Here are the actual results (the first classname is the
> > CL being used, and the subsequent classnames are the parents):
> >
> > Tomcat 3.1.1:
> > ----------------------------
> > CONTEXT CLASSLOADER:
> > org.apache.tomcat.loader.AdaptiveClassLoader@8df60
> > sun.misc.Launcher$AppClassLoader@71732b (parent)
> > sun.misc.Launcher$ExtClassLoader@7fdcde (parent)
> >
> >
> > CLASSLOADER:
> > org.apache.tomcat.loader.AdaptiveClassLoader@8df60
> > sun.misc.Launcher$AppClassLoader@71732b
> > sun.misc.Launcher$ExtClassLoader@7fdcde
> >
> >
> >
> >
> > Tomcat 3.2.3:
> > ----------------------------
> > CONTEXT CLASSLOADER:
> > sun.misc.Launcher$AppClassLoader@404536
> > sun.misc.Launcher$ExtClassLoader@7d8483
> >
> >
> > CLASSLOADER:
> > AdaptiveClassLoader( )
> > sun.misc.Launcher$AppClassLoader@404536
> > sun.misc.Launcher$ExtClassLoader@7d8483
> >
> >
> >
> > Tomcat 3.3 Beta 1:
> > ----------------------------
> > CONTEXT CLASSLOADER:
> > org.apache.tomcat.util.depend.DependClassLoader@71f189
> > sun.misc.Launcher$AppClassLoader@71732b
> > sun.misc.Launcher$ExtClassLoader@7fdcde
> >
> >
> > CLASSLOADER:
> > java.net.FactoryURLClassLoader@147496
> > java.net.FactoryURLClassLoader@724a9d
> > java.net.FactoryURLClassLoader@e3e60
> > sun.misc.Launcher$AppClassLoader@71732b
> > sun.misc.Launcher$ExtClassLoader@7fdcde
> >
> >
> >
> > Tomcat 4.0 Beta 6:
> > ----------------------------
> > CONTEXT CLASSLOADER & CLASSLOADER:
> > WebappClassLoader
> > available:
> > delegate: false
> > repositories:
> > /WEB-INF/classes/
> > required:
> > ----------> Parent Classloader:
> > StandardClassLoader
> > available:
> > delegate: false
> > repositories:
> > file:D:\jakarta\jakarta-tomcat-4.0-b6\lib\jasper-runtime.jar
> > file:D:\jakarta\jakarta-tomcat-4.0-b6\lib\namingfactory.jar
> > required:
> > ----------> Parent Classloader:
> > StandardClassLoader
> > available:
> > delegate: false
> > repositories:
> > file:D:\jakarta\jakarta-tomcat-4.0-b6\common\lib\naming.jar
> > file:D:\jakarta\jakarta-tomcat-4.0-b6\common\lib\resources.jar
> > file:D:\jakarta\jakarta-tomcat-4.0-b6\common\lib\servlet.jar
> > required:
> > ----------> Parent Classloader:
> > sun.misc.Launcher$AppClassLoader@71732b
> >
> > sun.misc.Launcher$ExtClassLoader@7fdcde
> >
>
>