Java – How to specify order of JAR class loading in weblogic

javaweblogicweblogic12c

I have an EAR file that contains two different jars that share some classes with an identical package.class name. These JARs are deployed in my APP-INF/lib directory.

Let's say A jar contains the latest version of classes and B contains the old version of classes. When a class is referenced Weblogic looks first into B jar and loads the old version which break some functionality.

How can I tell Weblogic to load jar A before B from APP-INF/lib? I need to define a specific order to avoid loading old classes.

I have already tried adding A jar to <classloader-structure> in weblogic-application.xml like so:

EAR structure:

EAR
\--->A.jar
\--->webapp.war
.....

weblogic-application.xml:

<classloader-structure> 
    <module-ref> 
        <module-uri>A.jar</module-uri> 
    </module-ref> 
    .......
 </classloader-structure>

but then it throws error saying

weblogic.management.DeploymentException: classloader-structure element in weblogic-application.xml is referencing the module-uri A.jar which does not exist in this application.

Also one thing to remember is that A.jar is not a module, war or EJB it just a plain hibernate library: hibernate-jpa-2.0-api-1.0.1.Final.jar

I am using Weblogic 12c version.

Best Answer

You need to set parent last strategy for class-loader, refer http://www.rgagnon.com/javadetails/java-0551.html, as i remember there is a GUI in weblogic server to do the same.

Related Topic