gpt4 book ai didi

tomcat - 类路径优先级中的 WEB-INF/classes/vs WEB-INF/lib/*.jar?

转载 作者:行者123 更新时间:2023-11-28 21:45:27 28 4
gpt4 key购买 nike

为tomcat webapp打包的war包含WEB-INF/classes和WEB-INF/lib/*.jar

它们中哪一个在 CLASSPATH 中具有更高的优先级?

我问的原因是,我的应用程序使用 A.jar,它包含从 aspectj 项目生成的方面;和 B.jar,它们将与 A.jar 的方面交织在一起。当编译项目 myapp 时,它会生成许多类,这些类会覆盖 B.jar 中的那些相同类,这些类被打包到 WEB-INF/classes 目录中。所以如果tomcat先加载WEB-INF/lib/*.jar,那么woven aspects不会生效

最佳答案

Tomcat有几个关于类加载器的文档:

引自 http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html :
(为便于阅读而添加换行符)

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 (see the common classloader definition above).

Last, any JAR containing servlet API classes will be ignored by the classloader.

All other class loaders in Tomcat 5 follow the usual delegation pattern.

Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this 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

所以 WEB-INF/classesWEB-INF/lib 之前被搜索。

关于tomcat - 类路径优先级中的 WEB-INF/classes/vs WEB-INF/lib/*.jar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8364619/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com