From: kkolinko
In a J2SE 2 (that is, J2SE 1.2 or later) environment, class loaders are +
In a Java environment, class loaders are arranged in a parent-child tree. Normally, when a class loader is asked to load a particular class or resource, it delegates the request to a parent class loader first, and then looks in its own repositories only if the parent -class loader(s) cannot find the requested class or resource. The model for -web application class loaders differs slightly from this, as discussed below, -but the main principles are the same.
+class loader(s) cannot find the requested class or resource. Note, that the +model for web application class loaders differs slightly from this, +as discussed below, but the main principles are the same.When Tomcat is started, it creates a set of class loaders that are organized into the following parent-child relationships, where the parent @@ -76,83 +77,109 @@ the following section.
As indicated in the diagram above, Tomcat creates the following class loaders as it is initialized:
$JAVA_HOME/jre/lib/ext). NOTE - Some JVMs may
+Bootstrap — This class loader contains the basic
+ runtime classes provided by the Java Virtual Machine, plus any classes from
+ JAR files present in the System Extensions directory
+ ($JAVA_HOME/jre/lib/ext). Note: some JVMs may
implement this as more than one class loader, or it may not be visible
- (as a class loader) at all.
CLASSPATH environment variable. All such
- classes are visible to both Tomcat internal classes, and to web
+ (as a class loader) at all.System — This class loader is normally initialized
+ from the contents of the CLASSPATH environment variable. All
+ such classes are visible to both Tomcat internal classes, and to web
applications. However, the standard Tomcat startup scripts
($CATALINA_HOME/bin/catalina.sh or
%CATALINA_HOME%\bin\catalina.bat) totally ignore the contents
of the CLASSPATH environment variable itself, and instead
build the System class loader from the following repositories:
+
$CATALINA_HOME/bin/bootstrap.jar — Contains the + main() method that is used to initialize the Tomcat server, and the + class loader implementation classes it depends on.
$CATALINA_BASE/bin/tomcat-juli.jar or
+ $CATALINA_HOME/bin/tomcat-juli.jar — Logging
+ implementation classes. These include enhancement classes to
+ java.util.logging API, known as Tomcat JULI,
+ and a package-renamed copy of Apache Commons Logging library
+ used internally by Tomcat.
+ See logging documentation for more
+ details.
If tomcat-juli.jar is present in
+ $CATALINA_BASE/bin, it is used instead of the one in
+ $CATALINA_HOME/bin. It is useful in certain logging
+ configurations
$CATALINA_HOME/bin/commons-daemon.jar — The classes
+ from Apache Commons
+ Daemon project.
+ This JAR file is not present in the CLASSPATH built by
+ catalina.bat|.sh scripts, but is referenced
+ from the manifest file of bootstrap.jar.
Common — This class loader contains additional + classes that are made visible to both Tomcat internal classes and to all + web applications.
+Normally, application classes should NOT
be placed here. The locations searched by this class loader are defined by
the common.loader property in
$CATALINA_BASE/conf/catalina.properties. The default setting will search the
- following locations in the order they are listed:
+ following locations in the order they are listed:
$CATALINA_BASE/lib$CATALINA_BASE/lib$CATALINA_HOME/lib$CATALINA_HOME/libBy default, this includes the following:
WebappX — A class loader is created for each web
application that is deployed in a single Tomcat instance. All unpacked
classes and resources in the /WEB-INF/classes directory of
- your web application archive, plus classes and resources in JAR files
- under the /WEB-INF/lib directory of your web application
- archive, are made visible to the containing web application, but to
- no others.
/WEB-INF/lib directory of your web application,
+ are made visible to this web application, but not to other ones.
As mentioned above, the web application class loader diverges from the -default Java 2 delegation model (in accordance with the recommendations in the -Servlet Specification, version 2.3, section 9.7.2 Web Application Classloader). +default Java delegation model (in accordance with the recommendations in the +Servlet Specification, version 2.4, section 9.7.2 Web Application Classloader). When a request to load a class from the web application's WebappX class loader is processed, this class loader will look in the local repositories first, instead of delegating before looking. There are exceptions. Classes which are -part of the JRE base classes cannot be overriden. For some classes (such as +part of the JRE base classes cannot be overridden. For some classes (such as the XML parser components in J2SE 1.4+), the J2SE 1.4 endorsed feature can be used. -Last, any JAR containing servlet API classes will be ignored by the -classloader. +Last, any JAR file that contains Servlet API classes will be explicitly +ignored by the classloader — Do not include such JARs in your web +application. All other class loaders in Tomcat follow the usual delegation pattern.
Therefore, from the perspective of a web application, class or resource @@ -162,18 +189,17 @@ loading looks in the following repositories, in this order:
Among many other changes, the JSE 5 release packages the JAXP APIs, and -a version of Xerces, inside the JRE. This has impacts on applications that -wish to use their own XML parser.
+Among many other changes, the JavaSE 5 release packages the JAXP APIs, and +a version of Apache Xerces, inside the JRE. This has impacts on applications +that wish to use their own XML parser.
In previous versions of Tomcat, you could simply replace the XML parser
in the $CATALINA_HOME/common/lib directory to change the parser