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 initialize the Tomcat 6 server, and the class loader implementation classes it depends on.包含用来初始化Tomcat 6服务器的main()方法,以及它所依赖的类装载器执行类。
o $CATALINA_HOME/bin/tomcat-juli.jar - Package renamed Jakarta commons logging API, and java.util.logging LogManager.包含重命名的包Jakarta commons logging API,以及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:
* Common - 这个类加载器包含额外的类,这些类可以被Tomcat内部类使用也可以被所有的web应用程序使用. 一般的, 应用程序的类不要放在这里. 这个类加载器可以看到所有在$CATALINA_HOME/lib目录下没有打包的类和资源,和JAR文件中的类和资源,默认包含下面这些:
o annotations-api.jar - JEE annotations classes.
o catalina.jar - Implementation of the Catalina servlet container portion of Tomcat 6.Tomcat 6中Catalina servlet容器的实现部分
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 jasper-jdt.jar - Eclipse JDT 3.2 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.基于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.为其他语言提供的可选的资源包。由于默认的资源包的内容也被包含在各个单独的jar文件中,如果没有国际化的需求,这些可选的资源包可以被安全的删除
* 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.为在单个Tomcat 6实例中被部署的每一个网络程序所产生的类装载器。在你的网络程序档案/WEB-INF/classes目录里所有的未打包的类和资源,以及web应用程序档案/WEB-INF/lib目录下JAR文件里的类和资源,可被这个Webapp里的程序使用,而不能其他程序使用。

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.
正如上面所讲的,web应用程序类加载器和默认的java 2 委派模型不同。(这是参照Servlet规范的建议, version 2.3,section 9.7.2 Web Application Classloader)。当web应用程序的WebappX类加载器加载一个类的时候,这个WebappX类加载器先在本地路径中查找,而不是委派给父亲. 这里有个例外。那些属于JRE基础类的部分不能被覆盖. 对于有些类 (例如J2SE 1.4+中的XML解析组件), J2SE 1.4 "授权标准覆盖机制"可以被使用. 最后, 任何包含servlet API 类的JAR文件被类加载器忽略。Tomcat 6中所有其他的类加载器依照通用的委派模型.

Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:因此,从一个web应用程序的角度来看,类和资源的装载以这样的顺序在下列路径中进行查找:

* 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/lib
* $CATALINA_HOME/lib/*.jar

XML Parsers and JSE 5

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.
JSE 5 内置了JAXP APIs, 和Xerces的一个版本。这影响到了希望使用自己的XML解析器的应用程序。

In previous versions of Tomcat, you could simply replace the XML parser in the $CATALINA_HOME/common/lib directory to change the parser used by all web applications. However, this technique will not be effective when you are running on JSE 5, because the usual class loader delegation process will always choose the implementation inside the JDK in preference to this one.
在以前的Tomcat版本中, 你可以简单的覆盖$CATALINA_HOME/common/lib目录下的XML解析器,就可以改变所有的web应用程序的用到的解析器. 但是, 在你运行JSE 5时,这个办法没用 , 因为常规的类装载器委派过程将总是优先选择JDK内部的实现.

JDK 1.5 supports a mechanism called the "Endorsed Standards Override Mechanism" to allow replacement of APIs created outside of the JCP (i.e. DOM and SAX from W3C). It can also be used to update the XML parser implementation. For more information, see: http://java.sun.com/j2se/1.5/docs/guide/standards/index.html.
JDK 1.5 支持一种叫做 "授权标准覆盖机制"的技术来允许替换为JCP的外部的API (例如:DOM and SAX from W3C). 这还可以被用来更新XML解析器的实现. 更多信息请参考: http://java.sun.com/j2se/1.5/docs/guide/standards/index.html.

Tomcat utilizes this mechanism by including the system property setting -Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS in the command line that starts the container.
Tomcat通过在启动容器的命令行里加入系统属性设置-Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS 来利用这个机制。
Running under a security manager

When running under a security manager the locations from which classes are permitted to be loaded will also depend on the contents of your policy file. See Security Manager HOW-TO for further information.
当在一个安全管理器下面运行时,从什么地方来的类可以被装载依赖于你的政策文件的具体内容。更多信息请参看Security Manager HOW-TO
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com
CVE-2021-25329 是 Apache Tomcat 服务器的一个安全漏洞,它影响了 Tomcat 9.0.0.M1 到 9.0.42 版本。该漏洞可以导致远程攻击者能够通过精心构造的请求,绕过访问控制限制,访问受限资源。 为了修复这个安全漏洞,请确保您的 Apache Tomcat 服务器升级到最新的版本。Apache Tomcat 团队已经发布了修复该漏洞的补丁版本,您可以从官方网站下载并安装最新的 Tomcat 版本。 另外,为了保护您的服务器免受潜在的攻击,还可以考虑以下建议: 1. 及时更新:确保您的 Apache Tomcat 服务器及相关软件都及时更新到最新版本,以获取最新的安全修复和功能改进。 2. 强化访问控制:审查和加强您的访问控制策略,限制对敏感资源的访问,并仅允许经过授权的用户或IP地址进行访问。 3. 配置安全性选项:根据最佳实践和安全建议,配置 Apache Tomcat 服务器的安全性选项,例如启用 SSL/TLS 加密、强密码策略等。 4. 安全审计和监控:定期进行安全审计和监控,及时检测和响应任何异常或可疑活动。 5. 安全意识培训:提高运维人员和开发人员的安全意识,教育他们关于安全最佳实践和常见攻击技术的知识。 请注意,以上建议仅供参考,具体的安全措施应根据您的具体环境和需求进行评估和实施。建议在升级或修改配置之前,先在测试环境中进行测试,确保没有不良影响。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值