简体   繁体   English

共享/类和战争文件下的Jave类-在Tomcat中加载的优先级

[英]Jave Class under shared/classes and war file - priority of loading in tomcat

Does anyone have a good understanding on the following scenario? 是否有人对以下情况有很好的了解?

A class can be deployed in tomcat in various locations. 一个类可以部署在tomcat的各个位置。 It can be simple .class or packed in a jar file. 它可以是简单的.class或打包在jar文件中。 I am listing those options here: 我在这里列出了这些选项:

apache-tomcat-6.0.35\\shared\\classes apache-tomcat-6.0.35 \\ shared \\ classes
apache-tomcat-6.0.35\\shared\\lib apache-tomcat-6.0.35 \\ shared \\ lib
apache-tomcat-6.0.35\\lib apache-tomcat-6.0.35 \\ lib
apache-tomcat-6.0.35\\webapps\\examples\\WEB-INF\\classes apache-tomcat-6.0.35 \\ webapps \\ examples \\ WEB-INF \\ classes
apache-tomcat-6.0.35\\webapps\\examples\\WEB-INF\\lib apache-tomcat-6.0.35 \\ webapps \\ examples \\ WEB-INF \\ lib

If the same class is deployed in all these locations (.class in classes folder hierarchy or packaged in a jar file and copied under *\\lib\\ hierarchy), what is the rule that tomcat's class loader would use to identify the class it would finally use? 如果在所有这些位置都部署了相同的类(.class在类文件夹层次结构中或打包在jar文件中,并在* \\ lib \\层次结构下复制),tomcat的类加载器将使用什么规则来识别最终将要使用的类?采用?

After doing more research I found the answer: 经过更多研究后,我找到了答案:

From tomcat official documentation site 从tomcat官方文档网站
Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order : 因此, 从Web应用程序的角度来看,类或资源的加载按以下顺序查找以下存储库

Bootstrap classes of your JVM JVM的Bootstrap类
System class loader classes (described above) 系统类加载器类(如上所述)
/WEB-INF/classes of your web application / WEB-INF /您的网络应用程序类
/WEB-INF/lib/*.jar of your web application Web应用程序的/WEB-INF/lib/*.jar
Common class loader classes (described above) 通用类加载器类(如上所述)

The locations searched by "Common class loader" are defined by the common.loader property in $CATALINA_BASE/conf/catalina.properties. “公用类加载器”搜索的位置由$ CATALINA_BASE / conf / catalina.properties中的common.loader属性定义。 This is where we enable/define share location; 这是我们启用/定义共享位置的地方; shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar shared.loader = $ {catalina.base} / shared / classes,$ {catalina.base} / shared / lib / *。jar

And the above order explains the logic. 以上顺序说明了逻辑。

This explains it quite well... 这很好地解释了...

http://www.mulesoft.com/tcat/tomcat-classpath#how-it-differs http://www.mulesoft.com/tcat/tomcat-classpath#how-it-differs

Notice that 注意

In Tomcat 5.x, a "shared" loader was responsible for loading classes to be shared between applications, located in the directory $CATALINA_HOME/shared/lib. 在Tomcat 5.x中,“共享”加载器负责加载应用程序之间共享的类,这些类位于目录$ CATALINA_HOME / shared / lib中。 This was abandoned in Tomcat 6, to steer users towards simply replicating shared dependencies in each of the dependent Contexts, for improved portability. 它在Tomcat 6中被放弃,以引导用户简单地在每个从属上下文中复制共享的从属关系,以提高可移植性。 This loader is also replaced with the Common loader. 该加载程序也被Common加载程序替代。

So if you are using Tomcat 6, "shared" is probably not working as you expect. 因此,如果您使用的是Tomcat 6,则“共享”可能无法按预期工作。

Ta,

-Bret -布雷

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM