Tomcat5.5 类装载器的实现都是通过继承于JDK中的 java.lang.ClassLoader类。
包括Bootstrap,System,Common, Catalina, Shared和Webapp这六种类加载器来实现不同目录的类文件装载。
Bootstrap
|
System
|
Common
/ \
Catalina Shared
/ \
Webapp1 Webapp2 ...
Bootstrap 类装载器:
它用于加载最基本的JVM运行环境类,装载JDK目录下类文件($JAVA_HOME/jre/lib/ext)
使用它的目的是以防一些JVM提供商实现时,可能考虑某些原因会把部分的类文件通过不同的多个类加载加器加载,同时会
屏蔽一些类加载让应用层的类加载器访问到。
System 类装载器:
该类装载器根据JVM的CLASSPATH参数设置装载类文件,该类装载器对于Tomcat内部的程序和应用层的程序都是可见的。
注:目前tomcat5的启动脚本($CATALINA_HOME/bin/catalina.sh 或 %CATALINA_HOME%\bin\catalina.bat),会把全局环境变量CLASSPATH忽略。
而且通过下面的几个类库来实现装载设置:
* $CATALINA_HOME/bin/bootstrap.jar 包含一个main()方法来初始化tomcat5服务,并实例类装器所依赖的类文件。
* $CATALINA_HOME/bin/tomcat-juli.jar 初始Jakarta commons logging API和 java.util.logging LogManager.
* $CATALINA_HOME/bin/commons-logging-api-x.y.z.jar - Jakarta commons logging API.
* $CATALINA_HOME/bin/commons-daemon.jar - Jakarta commons daemon API.
* jmx.jar - The JMX 1.2 implementation.
Common 类装载器:
该类装载器对于Tomcat内部的程序和应用层的程序都是可见的.
当然不太建议把应用层的类库放到这里来加载。
所有$CATALINA_HOME/lib目录下未压缩的类文件,资源和压缩后Jar/zip文件都会补该类装载器加载。
Tomcat5.5默认该目录的类文件有:
* 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 类装载器:
该类装载器用都装载tomcat5.5本身所需要的类文件和资源。应用层的类装载器不能访问到它。
所有$CATALINA_HOME/server/classes目录下未压缩的类文件,资源文件都会补该类装载器加载。
所有$CATALINA_HOME/server/lib目录下压缩后Jar/zip文件都会补该类装载器加载。
Tomcat5.5默认该目录的类文件有:
* 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.
Shared 类装载器:
该类装载器可化被所有的应用程序类装载器共享(除了tomcat本身内部类加载外)
所有$CATALINA_BASE/shared/classes目录下未压缩的类文件,资源文件都会补该类装载器加载。
所有$CATALINA_BASE/shared/lib目录下压缩后Jar/zip文件都会补该类装载器加载。
注: 如果有该类库使用$CATALINA_BASE环境变量启动了多个实例,则该类装载器类库的引使用会$CATALINA_BASE变量而不是$CATALINA_HOME
Webapp 类装载器:
应用层的类装载器,每个应用程序都会创建一个单独的类装载器。该类装载器只能本应用程序中可见。
所有/WEB-INF/classes目录下未压缩的类文件,资源文件都会补该类装载器加载。
所有/WEB-INF/lib目录下压缩后Jar/zip文件都会补该类装载器加载。
把各个类装载器的定义整理出来后,Tomcat5.5服务器类装载器执行的顺序如下:
* 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/i18n/*.jar
* $CATALINA_HOME/common/lib/*.jar
* $CATALINA_BASE/shared/classes
* $CATALINA_BASE/shared/lib/*.jar
Good Luck!
Yours Matthew!
posted on 2008-09-27 19:28
x.matthew 阅读(2108)
评论(1) 编辑 收藏 所属分类:
Application Server