如何在 EAR 中的 jar 和共享库之间的 Websphere Liberty Profile 中获取类加载器可见性

How to get classloader visibility in Websphere Liberty Profile between jar in EAR and shared library

我正在尝试让一些遗留代码在 Websphere Liberty Profile(最新版本 16)中工作。

此代码以库的架构集形式出现,我在 WLP 中将其设置为共享库,外加应用程序,它们作为 EAR

我遇到一个问题,其中一个库中的 jar 中的某些代码试图实例化 EAR 中的 class(在 lib 文件夹中的 jar 中)。

我得到这个堆栈跟踪:

Caused by: java.lang.ClassNotFoundException: com.isb.holamu.fnegocio.ln.AAL_FNegocioFactory <-- This class (1) is inside a .jar inside the EAR
       at com.ibm.ws.classloading.internal.AppClassLoader.findClassCommonLibraryClassLoaders(AppClassLoader.java:491)
       at com.ibm.ws.classloading.internal.AppClassLoader.findClass(AppClassLoader.java:274)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at com.ibm.ws.classloading.internal.AppClassLoader.findOrDelegateLoadClass(AppClassLoader.java:469)
       at com.ibm.ws.classloading.internal.AppClassLoader.loadClass(AppClassLoader.java:441)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Unknown Source)
       at com.isb.bs.bl.base.MetaFacadeFactory.createFactoryInstance(MetaFacadeFactory.java:74) <-- This class (2) is in the shared library in WLP.

这些是 server.xml 中的相关位:

   <!-- Server shared library -->

   <library id="architecture" >
         <fileset dir="${server.config.dir}/lib/jars" includes="*.jar" scanInterval="5s"/>  <-- (2) is here

   </library>

   <enterpriseApplication autoStart="true" id="sample" location="sample.ear" name="sample"> <-- (1) is here
         <classloader commonLibraryRef="architecture" delegation="parentFirst"/>
   </enterpriseApplication>

似乎 EAR classes 可以访问共享库 classloader 及其 classes,但共享库 classes 不能找到 EAR 中的那些。

任何人都可以提供任何关于如何让它工作的线索吗?

谢谢!

这不会起作用,因为公共库使用它们自己的 class 加载器,而不是引用它们的应用程序的加载器。

要使其正常工作,请将您的 commonLibraryRef 更改为 privateLibraryRef。这将有效地将库内容添加到应用程序的 class 路径。

--乔

最后我通过在应用程序标签内定义库来让它工作,如下所示:

<enterpriseApplication id="sample" location="sample.ear" name="sample">
    <classloader>
    <privateLibrary>
        <fileset dir="${server.config.dir}/lib/jars" includes="*.jar" scanInterval="5s"/> 
    </privateLibrary>
    </classloader>
</enterpriseApplication>