Overview of Tomcat class loading priorities

Source: Internet
Author: User
Tags bootstrap classes i18n
Overview of Tomcat class loading priorities

1. The first is the JAR file under $ java_home/JRE/lib/EXT.

2. jar and class files in the environment variable classpath.

3. $ catalina_home/common/classes Class file.

4. $ catalina_home/commons/endorsed JAR file.

5. $ catalina_home/commons/i18n.

6. $ catalina_home/common/lib.
(Jar files such as the JDBC driver can be placed here, so that the JDBC driver cannot be found after the data source is configured in server. xml .)
7. $ catalina_home/Server/classes Class file.

8. $ catalina_home/Server/lib.

9. $ catalina_base/shared/classes Class file.

10. $ catalina_base/shared/lib.

11. Their specific webapp/WEB-INF/classes under the class file.

12. Their specific webapp/WEB-INF/lib jar files.

The search sequence of the class is as follows:
-------------
Bootstrap classes of your JVM
System Class Loader Classses (described abve)
/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
--------------

Therefore, class files placed in different webapps are loaded into different instances by classloader.
For example, assume that the following two classes have different contents. Put them in the class directories of different webapps.

Package com. lizongbo;
Public class testclass {
Private string name = "lizongbo ";
}

Package com. lizongbo;
Public class testclass {
Private string name = "li_zongbo ";
}

The com. lizongbo. Name results obtained in different webapps are different and do not affect each other.

However, note that the following class exceptions start with the package name:
Javax .*
Org. xml. Sax .*
Org. W3C. Dom .*
Org. Apache. xerces .*
Org. Apache. xalan .*

PS, note. The class-path key-value pairs in the META-INFMAINFEST.MF files in each jar also provide the jar loading priority.
For example, the mainfest. MF content of a jar is as follows:
Manifest-version: 1.0
Created-by: lizongbo
Class-path: commons-beanutils.jar
Class-path: commons-collections.jar
Class-path: commons-dbcp.jar
Class-path: commons-digester.jar
Class-path: commons-logging.jar
Class-path: commons-pool.jar
Class-path: commons-services.jar
Class-path: commons-validator.jar
Class-path: jakarta-oro.jar
Main-class: COM. lizongbo. mytestclass

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.