In this blog post I suggest a very effective way to spot duplicated libs/classes in your java application. I found and used this tip during the integration phase on an application server – which is quite a common use case.
This tutorial will be very helpful in the following cases:
- NoClassDefFoundError: there are two different versions of the same class in your classpath.
- Integration with unknown huge products (not osgi-ed): detect multiple libs with the same version, and so reduce memory footprint.
Environment preparation
The first step to do – What? You haven’t already installed it? - is to install the Memory Analyzer Tool (MAT). Then you have to acquire a heap dump of your running application. These steps are explained in one of my previous blog post.
Easy and effective
Now that you have the heap dump with MAT, you are just three clicks away from spotting those annoying duplicated libs and version conflicting classes.
Go to Open Query browser->Java basics->Duplicated classes:
And here we are – you have the list of all duplicated classes with their classloaders:
Please notice that the class must be already loaded.
A last tip
Since you have made it this far, I will give you another little tip. You can find exactly from which lib the class was loaded using the Inspector view.
For instance, in case the duplicated class was loaded by an URLClassloader, just follow these steps:
- Select the class;
- Go to Inspector view in Attributes tab;
- Right-click on _context;
- and finally click go into.
Note: this was part of my EclipseCon Europe 2011 talk and one of my Eclipse Democamp Grenoble 2011 talk.





#1 by Sivaswami on February 15th, 2012
What if xml-ibm.jar is loaded instead of xml-sun.jar?
how to address this kind of conflict?
I want list
classloader A
– list of jar files loaded + list of classes loaded
classloader B
– list of jar files loaded + list of classes loaded
It would be better if MAT provides a dialog for class-jar-classloader mapping
#2 by Aurelien Pupier on February 22nd, 2012
Hi Sivaswami,
for xml-ibm and wml-sun jar, it won’t cause trouble.
To list class files loaded by a classloader, as indicated in the beginner tutorial included in MAT standalone, open class histogram and then select “Group by Classloader” from toolbar combobox (with three yellow box).
“It would be better if MAT provides a dialog for class-jar-classloader mapping”
I encourage you to open a feature request on MAT bugtracker: https://bugs.eclipse.org/bugs/enter_bug.cgi?product=MAT
Regards,