Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any tool to view the picture of class loader tree?

Say I'm debugging some weird class loading issues of an application deployed inside of a Java EE app server. By some reason it appears, that I have duplicate jars on the class paths of two classloaders (2 different EAR classloaders), and the classes from namespaces of these class loaders need to colaborate.

So the question is following: does exist any tool which can show an image (picture) of class loader tree together with the repository of each class loader? Of course, it's not of big importance to show exactly a picture, if it could be some kind of a dynamic user interface (i.e. like Windows Explorer tree folding/unfolding), I would be very happy.

UPD: I'm using JBoss 5.1.

Thanks

like image 780
Maksim Avatar asked Nov 04 '09 22:11

Maksim


People also ask

How does ClassLoader work in Java?

A Java Class is stored in the form of byte code in a . class file after it is compiled. The ClassLoader loads the class of the Java program into memory when it is required. The ClassLoader is hierarchical and so if there is a request to load a class, it is delegated to the parent class loader.

How do I know what ClassLoader loads a class?

To know the ClassLoader that loads a class the getClassLoader() method is used. All classes are loaded based on their names and if any of these classes are not found then it returns a NoClassDefFoundError or ClassNotFoundException.

What are different types of class loaders?

As we can see, there are three different class loaders here: application, extension, and bootstrap (displayed as null). The application class loader loads the class where the example method is contained. An application or system class loader loads our own files in the classpath.

What is a class loader example?

For example, java. lang package class. Extensions Class Loader: It delegates class loading request to its parent. If the loading of a class is unsuccessful, it loads classes from jre/lib/ext directory or any other directory as java.


1 Answers

In JBoss you can log all classloader events, which should tell you precisely where your conflicting classes are, if you can sift through the verbosity.

Or you can go to the jmx-console, find the jboss.classloader section, find the entry for your ear (something like id="vfszip:/apps/jboss-5.1.0.GA/server/default/deploy/your.war/") and invoke findClassLoaderForClass for the class that's giving you problems.

like image 56
pra Avatar answered Oct 27 '22 12:10

pra