|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectclasspathhelper.tomcat.listener.TomcatClassLoaderService
classpathhelper.tomcat.listener.VersionFiveTomcatClassLoaderService
Instance of the ITomcatClassLoaderService
that
mimics the version 5 classloading properties of Apache's
Tomcat. The following is an excerp directly from the
5.5 documentation.
Like many server applications, Tomcat 5 installs a variety of class loaders (that is, classes that implement java.lang.ClassLoader) to allow different portions of the container, and the web applications running on the container, to have access to different repositories of available classes and resources. This mechanism is used to provide the functionality defined in the Servlet Specification, version 2.4 -- in particular, Sections 9.4 and 9.6.
In a J2SE 2 (that is, J2SE 1.2 or later) 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.
When Tomcat 5 is started, it creates a set of class loaders that are organized into the following parent-child relationships, where the parent class loader is above the child class loader:
Bootstrap
|
System
|
Common
/ \
Catalina Shared
/ \
Webapp1 Webapp2 ...
The characteristics of each of these class loaders,
including the source of classes and resources that they make
visible, are discussed in detail in the following section.
As indicated in the diagram above, Tomcat 5 creates the
following class loaders as it is initialized:
$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.$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 5
server, and the class loader implementation classes it depends
on.$JAVA_HOME/lib/tools.jar
- Contains the "javac"
compiler used to convert JSP pages into servlet classes.$CATALINA_HOME/bin/commons-logging-api.jar
-
Jakarta commons logging API.$CATALINA_HOME/bin/commons-daemon.jar
- Jakarta
commons daemon API.jmx.jar
- The JMX 1.2 implementation.$CATALINA_HOME/common/classes
, as
well as classes and resources in JAR files under the
$CATALINA_HOME/common/endorsed
,
$CATALINA_HOME/common/i18n
and
$CATALINA_HOME/common/lib
directories, are made
visible through this class loader. By default, that includes
the following:
commons-el.jar
- Jakarta commons el,
implementing the expression language used by Jasper.jasper-compiler.jar
- The JSP 2.0 compiler.jasper-compiler-jdt.jar
- The Eclipse JDT
Java compiler.jasper-runtime.jar
- The JSP 2.0 runtime.jsp-api.jar
- The JSP 2.0 API.naming-common.jar
- The JNDI implementation
used by Tomcat 5 to represent in-memory naming contexts.naming-factory.jar
- The JNDI implementation
used by Tomcat 5 to resolve references to enterprise
resources (EJB, connection pools).naming-factory-dbcp.jar
- Jakarta commons
DBCP, providing a JDBC connection pool to web applications. The
classes have been moved out of their default
org.apache.commons
package.naming-java.jar
- Handler for the java:
namespace.naming-resources.jar
- The specialized JNDI
naming context implementation used to represent the static
resources of a web application. This is not related to the
support of the J2EE ENC, and cannot be removed.servlet-api.jar
- The Servlet 2.4 API.tomcat-i18n-**.jar
- Optional JARs
containing resource bundles for other languages. As default
bundles are also included in each individual JAR, they can
be safely removed if no internationalization of messages is
needed.$CATALINA_HOME/server/classes
, as well as
classes and resources in JAR files under
$CATALINA_HOME/server/lib
, are made visible
through this class loader. By default, that includes the
following:
catalina.jar
- Implementation of the
Catalina servlet container portion of Tomcat 5.catalina-ant.jar
- Some Ant tasks which can
be used to manage Tomcat using the manager web application.catalina-optional.jar
- Some optional
components of Catalina.commons-modeler.jar
- A model MBeans
implementation used by Tomcat to expose its internal objects
through JMX.servlets-xxxxx.jar
- The classes associated
with each internal servlet that provides part of Tomcat's
functionality. These are separated so that they can be
completely removed if the corresponding service is not
required, or they can be subject to specialized security
manager permissions.tomcat-coyote.jar
- Coyote API.tomcat-http.jar
- Standalone Java HTTP/1.1
connector.tomcat-ajp.jar
- Classes for the Java
portion of the AJP web server connector, which allows
Tomcat to run behind web servers such as Apache and iPlanet
iAS and iWS.tomcat-util.jar
- Utility classes
required by some Tomcat connectors.$CATALINA_BASE/shared/classes
, as well as
classes and resources in JAR files under
$CATALINA_BASE/shared/lib
, are made visible
through this class loader. If multiple Tomcat instances are
run from the same binary using the $CATALINA_BASE
environment variable, then this classloader repositories are
relative to $CATALINA_BASE
rather than
$CATALINA_HOME
./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.
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). 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 the XML parser components in J2SE
1.4+), the J2SE 1.4 endorsed feature can be used (see the
common classloader definition above). In addition, for the
following class patterns, the classloader will always
delegate first (and load the class itself if no parent
classloader loads it):
Last, any JAR containing servlet API classes will be ignored
by the classloader. All other class loaders in Tomcat 5
follow the usual delegation pattern.javax.*
org.xml.sax.*
org.w3c.dom.*
org.apache.xerces.*
org.apache.xalan.*
Therefore, from the perspective of a web application, class or
resource loading looks in the following repositories, in this
order:
/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/i18n/*.jar
$CATALINA_HOME/common/lib/*.jar
$CATALINA_BASE/shared/classes
$CATALINA_BASE/shared/lib/*.jar
Field Summary |
Fields inherited from class classpathhelper.tomcat.listener.TomcatClassLoaderService |
properties |
Constructor Summary | |
protected |
VersionFiveTomcatClassLoaderService(TomcatProperties theProperties)
Basic constructor, not called directly, instances of this class are provided via TomcatClassLoaderService.getService(TomcatProperties) . |
Method Summary | |
protected static java.lang.String |
convertPathsToPath(java.util.List paths)
Internal method that takes a list of File
and File[] objects and appends them to
a string in a classic classpath format. |
CGClassLoader |
createClassLoader(java.lang.String appName,
CGClassLoaderFilter filter,
FileChangeMonitor fileMonitor)
Method that creates the appropriate class loader hierarchy consistent with the associated instance of Tomcat and the supplied application. |
protected static java.io.File[] |
enumerateJars(java.io.File root)
Internal method that enumerates the jar files at the path supplied. |
java.lang.String[] |
getAppNames()
Returns an array of application names in the associated Tomcat instance. |
Methods inherited from class classpathhelper.tomcat.listener.TomcatClassLoaderService |
getService |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected VersionFiveTomcatClassLoaderService(TomcatProperties theProperties)
TomcatClassLoaderService.getService(TomcatProperties)
.
theProperties
- The properties associate with this instance
of Tomcat.Method Detail |
protected static java.io.File[] enumerateJars(java.io.File root)
root
- The root dir to look up files in.
.jar
or .zip
protected static java.lang.String convertPathsToPath(java.util.List paths)
File
and File[]
objects and appends them to
a string in a classic classpath format.
paths
- The list of files and file arrays.
public java.lang.String[] getAppNames()
ITomcatClassLoaderService
ITomcatClassLoaderService.createClassLoader(java.lang.String, classpathhelper.CGClassLoaderFilter, classpathhelper.filechangelistener.FileChangeMonitor)
.public CGClassLoader createClassLoader(java.lang.String appName, CGClassLoaderFilter filter, FileChangeMonitor fileMonitor)
ITomcatClassLoaderService
appName
- The application name, should be
a value from ITomcatClassLoaderService.getAppNames()
.filter
- The filter for the class loader.fileMonitor
- An optional (may be null) file monitor
that will be populated with the files to monitor related
to this classloader.
null
if
the application name is invalid.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |