tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christopher Piggott" <>
Subject Classloading questions
Date Sun, 30 Apr 2006 14:26:39 GMT

As an experiment, I placed a file in the webapp dir of a servlet (not in
WEB-INF but in the directory above it) and attempted to read it using
getResource().  What I found was that I could not locate the resource unless
I used getServletContext().getResource().

Reading through the Classloading How-To, I am confused why this works.  The
how-to says that from the perspective of the webapp, loading takes place in
this order:

    * Bootstrap classes of your JVM
    * System class loader classses (described above)
    * /WEB-INF/classes of your web application
    * /WEB-INF/lib/*.jar of your web application
    * $CATALINA_HOME/common/classes
    * $CATALINA_HOME/common/endorsed/*.jar
    * $CATALINA_HOME/common/lib/*.jar
    * $CATALINA_BASE/shared/classes
    * $CATALINA_BASE/shared/lib/*.jar

But, what is the order for getServletContext() ?

To try to figure this out, I ran another experiment:

	ClassLoader c1 = this.getClass().getClassLoader();
	log(" this's classloader is " + c1.getClass().getName());

	ClassLoader c2 = getServletContext().getClass().getClassLoader();
	log(" servlet context's  classloader is " + c2.getClass().getName());


	this's classloader is org.apache.catalina.loader.WebappClassLoader
	servlet context's  classloader is

The HowTo says the following classloaders exist:

    * Bootstrap
    * System
    * Common
    * Catalina
    * Shared
    * WebappX

How is that some instance of StandarClassLoader able to access the webapp

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message