tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob Shaw" <>
Subject Re: Class loading & classloader visibility test results
Date Wed, 06 Dec 2000 05:50:55 GMT

Based on the stack trace alone it's difficult to debug the problem.

If you want everything to be self contained within your context,
then the first thing I would ensure is that every class required
by your servlet is contained with the classes or lib directory
of your context.

Also, since the system  classloader is used prior to your
webapp's classloader, ensure that your system
classpath is clean to avoid inadvertent loading of classes.

Ideally this is all you would have to do.

As a long shot, I've run into the following gotcha which may
apply to xml4j.

I've run into problems with code that attempts to grab
the current classloader in the following way: 
         Object object = new Object();
         ClassLoader loader = object.getClass().getClassLoader();

I've found that the classloader retrieved in this manner is
unable to load classes from within my context.  My rationale
for this is because java.lang.Object is loaded and instantiated
via the system classloader, and thus the system classloader is
Instead you want to do something like:

         ClassLoader loader = getClass().getClassLoader();

which should return your webapp's classloader.

Hopefully this helps.

----- Original Message ----- 
From: "Aron Kramlik" <>
To: <>
Sent: Tuesday, December 05, 2000 8:36 PM
Subject: RE: Class loading & classloader visibility test results

> Rob,
> This is great information.  I wonder if you could explain
> why it is that I need to put xml4j.jar file under the $CLASSPATH
> (i.e. $TOMCAT_HOME/lib) that is loaded by an init() method of
> a servlet?
> Once I do this the class,, is found.
> Stack trace below.
> Anyh help would be much appreciated.
> Thanks again for the great info,
> Aron.
> java.lang.ClassNotFoundException:
>     at java.lang.Throwable.<init>(
>     at java.lang.Exception.<init>(
>     at
> java.lang.ClassNotFoundException.<init>(
>     at
>     at java.lang.ClassLoader.loadClass( Code))
>     at sun.misc.Launcher$AppClassLoader.loadClass(
>     at java.lang.ClassLoader.loadClass(
>     at java.lang.Class.forName1(Native Method)
>     at java.lang.Class.forName(
>     at org.xml.sax.helpers.ParserFactory.makeParser(
>     at com.tenzing.servlet.InitServlet.setXMLParser(
>     at
> com.tenzing.servlet.InitServlet.initializeConfiguration(
> )
>     at com.tenzing.servlet.InitServlet.init(
>     at org.apache.tomcat.core.ServletWrapper.doInit(
> -----Original Message-----
> From: Rob Shaw []
> Sent: Tuesday, December 05, 2000 2:49 PM
> To:
> Subject: Class loading & classloader visibility test results
> For those that may be interested...
> I was unclear as to how Tomcat was resolving class
> loading and the visibility of classes to a context's
> classloader so I created a simlpe test suite.
> The test results are attached.
> Rob Shaw
> Servidium Inc.

View raw message