日期:2014-05-17  浏览次数:20769 次

Apache Tomcat 6.0 Class Loader HOW-TO翻译
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.
    象许多服务器程序一样,Tomcat 6安装了各种不同类型的类加载器(即实现了java.lang.ClassLoader的类)来允许容器的不同部分,以及运行在容器上的web应用程序,可以访问不同贮存部分的类和资源。这个机制是用来提供Servlet Specification, 2.4版——特别是9.4 和 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.
    在J2SE 2 (即J2SE 1.2 或者以后的版本) 环境中, 类装载器们被组织在一个有父子关系的树状结构中。一般, 一个类装载器被请求载入一个类或者资源, 它先将这个请求转发给父亲类装载器, 并且只有在父亲不能装载这个类或者资源的时候才在自己的路径去搜寻。如下描述的,web应用程序类装载模型和这有一些小的差别,但是基本原理是一样的。
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:
当Tomcat 6启动时,它创建一组类装载器,这些类装载器被组织成如下的父子关系,父类装载器在子类装载器之上:

      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:
如上面的图表显示,Tomcat 6在它启动时产生如下的类装载器:
        * 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.
        * Bootstrap - 这个类装载器包含Java虚拟器提供的基本的运行时间类,加上在System Extensions 目录( $JAVA_HOME/jre/lib/ext )里的JAR文件中所有的类。注意——也许有些Java虚拟器(JVMs)包含不止一个Bootstrap类装载器,或者也许是不可见的(作为一个类装载器)。

        * 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:
        * System - 这个类装载器通常是以CLASSPATH环境变量的内容为基础来初始化的。所有的这些类既可被Tomcat内部classes使用,又可被web应用程序使用。不过,标准的Tomcat 6启动脚本( $CATALINA_HOME/bin/catalina.sh or %CATALINA_HOME%\bin\catalina.bat )完全忽略了CLASSPATH环境变量自身的内容,相反从下面的贮藏室去建造系统类装载器:
              o $CATALINA_HOME/bin/bootstrap.jar - Contains the main() method that is used to