http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html
Overview
Like many server applications, Tomcat 6 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 6 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
/ \
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.
Class Loader Definitions
As indicated in the diagram above, Tomcat 6 creates the following class loaders as it is initialized:
* 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.
* 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 6 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:
o $CATALINA_HOME/bin/bootstrap.jar - Contains the main() method that is used to initialize the Tomcat 6 server, and the class loader implementation classes it depends on.
o $CATALINA_HOME/bin/tomcat-juli.jar - Package renamed Commons logging API, and java.util.logging LogManager.
* 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. All unpacked classes and resources in $CATALINA_HOME/lib, as well as classes and resources in JAR files are made visible through this class loader. By default, that includes the following:
o annotations-api.jar - JEE annotations classes.
o catalina.jar - Implementation of the Catalina servlet container portion of Tomcat 6.
o catalina-ant.jar - Tomcat Catalina Ant tasks.
o catalina-ha.jar - High availability package.
o catalina-tribes.jar - Group communication package.
o el-api.jar - EL 2.1 API.
o jasper.jar - Jasper 2 Compiler and Runtime.
o jasper-el.jar - Jasper 2 EL implementation.
o ecj-*.jar - Eclipse JDT Java compiler.
o jsp-api.jar - JSP 2.1 API.
o servlet-api.jar - Servlet 2.5 API.
o tomcat-coyote.jar - Tomcat connectors and utility classes.
o tomcat-dbcp.jar - package renamed database connection pool based on Commons DBCP.
o 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.
* WebappX - A class loader is created for each web application that is deployed in a single Tomcat 6 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.
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. Last, any JAR containing servlet API classes will be ignored by the classloader. All other class loaders in Tomcat 6 follow the usual delegation pattern.
Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:
* Bootstrap classes of your JVM
* System class loader classes (described above)
* /WEB-INF/classes of your web application
* /WEB-INF/lib/*.jar of your web application
* $CATALINA_HOME/lib
* $CATALINA_HOME/lib/*.jar
分享到:
相关推荐
开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-...
apache-tomcat-8.5.78-windows-x64安装包 apache-tomcat-8.5.78-windows-x64安装包 apache-tomcat-8.5.78-windows-x64安装包 apache-tomcat-8.5.78-windows-x64安装包 apache-tomcat-8.5.78-windows-x64安装包 ...
Apache Tomcat 6.0是Java Web应用服务器,主要用于运行基于Java Servlet和JavaServer Pages (JSP)的应用程序。它是Apache软件基金会Jakarta项目的一部分,以其开源、免费和高效的特性深受开发者喜爱。在这个版本中,...
安装Apache Tomcat 6.0通常包括解压下载的`apache-tomcat-6.0.33`压缩包,设置环境变量如`CATALINA_HOME`,以及配置`conf/server.xml`文件以定义端口、虚拟主机和应用上下文路径。 **部署Web应用** Web应用程序通常...
apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-...
标题中的问题“Target runtime Apache Tomcat 6.0 is not defined”是Eclipse IDE中一个常见的错误提示,意味着用户在尝试运行或部署基于Apache Tomcat 6.0的应用时,Eclipse无法找到对应的运行时环境。这个错误通常...
Apache Tomcat 6.0是Java Servlet和JavaServer Pages(JSP)的开源Web应用程序服务器,由Apache软件基金会开发和维护。它是一个轻量级应用服务器,特别适合部署Java Web应用。以下是对Apache Tomcat 6.0安装版的详细...
在解压后的`apache-tomcat-6.0.18`目录中,你会找到以下几个关键文件和目录: - **bin**:包含用于启动、停止和管理Tomcat的脚本。 - **conf**:存放服务器的配置文件,如server.xml、web.xml等。 - **lib**:包含...
在本压缩包"apache-tomcat-6.0.29.zip"中,包含的是Apache Tomcat 6.0.29版本的源码、配置文件、库文件以及相关的文档资料。 Tomcat 6.0.29是Apache Tomcat的一个稳定版本,发布于2010年,支持Java EE 5规范。以下...
Apache Tomcat 6.0是Apache软件基金会的一个开源项目,主要功能是作为Java Servlet和JavaServer Pages(JSP)的应用服务器。它是一个轻量级、高性能的Web应用服务器,广泛用于部署Java Web应用程序。本篇文章将详细...
apache-tomcat-6.0.35-windows-x64.zip apache-tomcat-6.0.35-windows-x86.zip apache-tomcat-7.0.29-windows-x64.zip apache-tomcat-7.0.29-windows-x86.zip
这里我们关注的是"apache-tomcat-8.0.53-windows-x64"和"tomcat 6.0"这两个版本。 1. **Tomcat 8.0.53**: 这是Apache Tomcat的一个具体版本,发布于2017年。Tomcat 8引入了许多新特性和改进,包括对Java EE 7标准的...
Apache Tomcat 6.0 是一个广泛使用的开源软件,它是一个符合Java Servlet和JavaServer Pages (JSP) 规范的应用服务器,主要用来部署和运行Java Web应用程序。这个版本是Tomcat系列的6.0版,它在当时的发布中提供了...
这个压缩包 "apache-tomcat-8.5.98-windows-x64.zip" 包含了适用于Windows 64位操作系统的Apache Tomcat 8.5.98版本。该版本是Tomcat的稳定版本之一,提供了对Java EE 7规范的支持。 Apache Tomcat的核心功能是作为...
apache-tomcat-10.1.19-windows-x64
在本例中,我们关注的是`apache-tomcat-7.0.63-windows-x64.zip`这个文件,这代表了Tomcat 7.0.63版本的64位Windows构建。 **Apache Tomcat的概述** Apache Tomcat是一个轻量级应用服务器,它实现了Java EE中的...
这个“apache-tomcat-9.0-windows-x64.zip”压缩包包含了专为64位Windows操作系统设计的Tomcat 9.0的三个不同版本。下面将详细介绍这些版本以及与之相关的知识点。 1. **Java Servlet和JSP**: Tomcat是Java Servlet...
Apache Tomcat 6.0是一款广泛应用的开源Java Servlet容器,由Apache软件基金会开发并维护。作为轻量级的Web服务器和应用服务器,Tomcat主要负责运行基于Java EE Web应用程序,尤其是Servlet和JSP。它的“绿色”特性...
Apache Tomcat 6.0是Apache软件基金会的开源项目,是一个流行的Java Servlet容器,用于运行Java Web应用程序。源代码分析可以帮助我们深入理解Tomcat的工作原理,优化性能,以及进行自定义扩展。下面是关于Apache ...