WEB-INF/classes/与WEB-INF/lib/*.jar在类路径优先级? [英] WEB-INF/classes/ vs WEB-INF/lib/*.jar in classpath priority?

查看:202
本文介绍了WEB-INF/classes/与WEB-INF/lib/*.jar在类路径优先级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为tomcat Webapp打包的战争包含WEB-INF/classes和WEB-INF/lib/*.jar

a war packaged for a tomcat webapp contains WEB-INF/classes and WEB-INF/lib/*.jar

其中哪个在CLASSPATH中具有更高的优先级?

which of them has higher priority in the CLASSPATH?

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

the reason I'm asking is, that my application uses A.jar, which contains aspects generated from an aspectj project; and B.jar, which are to be woven with the aspects from A.jar. when the project myapp is compiled, it generates many Classes which override those same classes from B.jar, these are packaged into the WEB-INF/classes dir. so if tomcat load WEB-INF/lib/*.jar first, then the woven aspects won't take effect

推荐答案

当处理从Web应用程序的WebappX类加载器加载类的请求时,该类加载器将首先在本地存储库中查找,而不是在查找之前委派.也有例外.属于JRE基类的类不能被覆盖.对于某些类(例如J2SE 1.4+中的XML解析器组件),可以使用J2SE 1.4认可的功能(请参见上面的通用类加载器定义).最后,任何包含servlet API类的JAR都将被类加载器忽略. Tomcat 5中的所有其他类加载器都遵循通常的委派模式.

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.

因此,从Web应用程序的角度来看,类或资源的加载是按以下顺序在以下存储库中进行的:

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/classs,然后再搜索WEB-INF/lib

So WEB-INF/classes is searched first before WEB-INF/lib

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

这篇关于WEB-INF/classes/与WEB-INF/lib/*.jar在类路径优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆