Feb 24, 2014

Troubleshooting Java classloader or class loading issues -- Weblogic example

Every Java developer faces the following issue from time to time.

"I thought that I was using my application package version of a library but apparently my application server (e.g. Weblogic, JBoss) has already loaded an older version of this-library-issue"

These issues normally arise when there are certain classes which are packaged along with Application Server as part of common libraries and the same set of classes are also present in our Application package as well (normally inside WEB-INF/lib folder of the application). The reasons for the problem lies with how the class loading works in any Application Server. Different Application Servers provide different mechanisms to deal with this problem. 

Recently I faced the similar issue with loading my MOXy libraries for marshaling and marshaling XML to and from Java objects. Troubleshooting these issues could be tricky. and luckily the eclipse link MOXy library had a org.eclipse.persistence.Version.getVersion( ), which prints the version of the library used. In my case, an older version was used from the Weblogic lib directory, ignoring the later version packed in my war or ear package.

Solving it when you deploy a war file in Weblogic server.

The web logic specific web deployment descriptor file weblogic.xml file shown below hinting weblogic to use the jar libraries included the WEB-INF/lib for the listed packages like org.eclipse.persistence.*.

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="" xmlns:xsi="" xsi:schemaLocation="">



Solving it when you deploy an ear file in Weblogic server.

Similarly, if you have an ear file, and the the library is packaged within /lib folder. The ear descriptor file weblogic-application.xml  will look like

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application xmlns:wls="" xmlns:xsi=""

Refer to Weblogic documentation for other options like "prefer-web-inf-classes" element. 

Labels: ,


Post a Comment

Subscribe to Post Comments [Atom]

<< Home