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