[英]Weblogic application classloading of utility jar classes from other jars in the same webapp
I am faced with a puzzle around some classloading issues with my application in Weblogic. 我在Weblogic的应用程序中遇到一些类加载问题的困惑。 There are some places in my code where there are classes which depend on classes from other jars and I must be missing something fundamental. 在我的代码中的某些地方,有一些类依赖于其他jar中的类,因此我必须缺少一些基本知识。
From reviewing information I can find, this shouldn't be a problem if both jars are on the classpath, but this seems to be more subtle in a Java EE application context on Weblogic. 通过查看信息可以发现,如果两个jar都位于类路径上,这应该不成问题,但是在Weblogic上的Java EE应用程序上下文中,这似乎更加微妙。
I have an Ear, MyApp.ear 我有一个耳朵MyApp.ear
MyApp.ear contains several webapps (war) and a whole bunch of utility jars and EJBs. MyApp.ear包含多个web应用程序(战争)以及一堆实用程序jar和EJB。 Structure is something like this ( I don't control it). 结构是这样的(我不控制)。
MyApp.ear
MyWebApp.war
UtilJar1.jar
UtilJar2.jar
etc...
Let's say that there are classes in UtilJar1 that import classes from UtilJar2. 假设UtilJar1中有一些类从UtilJar2导入类。 What MANIFEST.MF should specify that both jars should be on the classpath? 哪个MANIFEST.MF应该指定两个jar都应该在类路径上? The EAR's? 耳朵? The Webapp's? Webapp的? UtilJar1's? UtilJar1的?
From trial and error (Weblogic 10.3.2), the only way that this seems to work is if UtilJar2 is defined in the Manifest class-path of UtilJar1. 从反复试验(Weblogic 10.3.2)来看,似乎唯一可行的方法是如果在UtilJar1的清单类路径中定义了UtilJar2。 But I would have thought that in the context of a webapp that the webapp's classpath would be used for any classloading happening in that webapp? 但是我会认为,在Web应用程序的上下文中,Web应用程序的类路径将用于该Web应用程序中发生的任何类加载? Instead I see NoClassDefFound unless the second jar is specified in the classpath of the first. 相反,除非在第一个jar的类路径中指定了第二个jar,否则我会看到NoClassDefFound。
Below is an excerpt from oracle documentation: 以下是oracle文档的摘录:
The J2EE specification provides the manifest Class-Path entry as a means for a module to specify that it requires an auxiliary JAR of classes. J2EE规范提供清单类路径条目,作为模块指定它需要类的辅助JAR的一种方式。
You only need to use this manifest Class-Path entry if you have additional supporting JAR files as part of your EJB JAR or WAR file. 仅当您有其他支持的JAR文件作为EJB JAR或WAR文件的一部分时,才需要使用此清单类路径条目。
Please go through the Manifest Class-Path section in the below documentation - 请仔细阅读以下文档中的清单类路径部分-
J2ee deployment archive [EAR] is an assembly of different modules with each module declaring there dependencies in there respective manifest files. J2ee部署档案库[EAR]是不同模块的组合,每个模块在相应的清单文件中声明依赖关系。
As per my understanding, each module [ war, ejb,jar] inside EAR will have there own class loaders which are children to EAR class loader. 根据我的理解,EAR中的每个模块[war,ejb,jar]都会有自己的类加载器,它们是EAR类加载器的子级。 And child class loaders will have visibility of their parents only and are unaware of the sibling class loaders unless you declare the dependencies in Manifest file. 除非您在清单文件中声明依赖项,否则子类加载器将仅对其父级具有可见性,并且不会意识到同级类加载器。
Even though there is an entry in WAR manifest, utilit1.jar is unaware of utility2.jar and you have to explicitly mention the dependency in Manifest file of Utility1.jar. 即使在WAR清单中有一个条目,utilit1.jar也不知道Utility2.jar,您必须在Utility1.jar的清单文件中明确提及依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.