How to get visibility of the class loader in Websphere Liberty Profile between jar in EAR and the shared library


I'm trying to get some legacy code working in a Websphere Liberty Profile (latest version 16).

This code comes in form of an architectural set of libraries, which I have set up as shared libraries in WLP, plus applications, which come as EARs

I'm getting a problem where some code in on of the jar in one of the libraries tries to instantiate a class which is inside the EAR (in a jar in the lib folder).

I'm getting this stacktrace:

Caused by: java.lang.ClassNotFoundException: com.isb.holamu.fnegocio.ln.AAL_FNegocioFactory <-- This class (1) is inside a .jar inside the EAR
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Unknown Source)
       at <-- This class (2) is in the shared library in WLP.

And these are the relevant bits from the server.xml:

   <!-- Server shared library -->

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


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

It seems as if the EAR classes can access the shared library classloader and its classes, but the shared library classes can't find the ones inside the EAR.

Can anyone give any clue on how to get this working?


This will not work because common libraries use their own class loaders, not those of the apps that reference them.

To make this work, change your commonLibraryRef to a privateLibraryRef. This will effectively add the library content to the app's class path.