WEB-INF / classes / vs WEB-INF / lib / *. Jar in classpath priority?

The war, packaged for the tomcat web application, contains WEB-INF / classes and WEB-INF / lib / *. jar

which one takes precedence in CLASSPATH?

the reason I'm asking for is because my application uses A.jar, which contains aspects generated from the aspectj project; and B.jar, which should be intertwined with aspects from A.jar. when the myapp project is compiled, it generates many classes that override the same classes from B.jar, they are packed into the WEB-INF / classes directory. therefore, if tomcat first loads WEB-INF / lib / *. jar, then the woven aspects will not take effect.

+7
source share
2 answers

When a request to load a class from a web application is processed, the WebappX class loader is processed, this class loader will first search in local repositories, and not delegate it before searching. There are exceptions. Classes that are part of JRE base classes cannot be overestimated. For some classes (such as XML parser components in J2SE 1.4+), you can use the function supported by J2SE 1.4 (see General definition of the class loader above). Finally, any JAR class containing servlet API classes will be ignored by the class loader. All other class loaders in Tomcat 5 follow the usual delegation pattern.

Therefore, from the point of view of a web application, loading classes or resources looks in the following repositories in the following order:

Bootstrap classes of your JVM System class loader classes (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 

Thus, the search for WEB-INF / classes is performed before WEB-INF / lib

Link: http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html

+11
source

If you put classes in WEB-INF / classes, they take precedence over banks in WEB-INF / lib. I sometimes used this for debugging purposes. See also here .

+2
source

All Articles