Find the ClassLoader loading a specific class

paweloque :

Is there a way to determine which ClassLoader loads a specific class? Or more specifically from where a specific class is loaded?

I've a situation where an old db driver class is loaded. I'd like to find the file where the old driver is loaded from.

My initial approach is to set a debug point on the ClassLoader.loadClass(..) method and stop the vm once the class is getting loaded to see which classloader is loading it. Unfortunately the loadClass method is called so often that its difficult to stop where the class is loaded. I'll try to set a breakpoint filter. There is, however, another problem: because of the ClassLoader architecture the loadClass is called even if the ClassLoader is not responsible for loading.

There must be a better way to achieve what I want. Do you have an idea or suggestion where to look for a solution?

sgp15 :

How do you launch your program?

Adding following option to command line logs location of every class being loaded.

-verbose:class

These logs typically appear in sysout. But depending on how logging is configured you may have to look around a little.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Classloader loading a class for None when foreach is used on it

Difference between Loading a class using ClassLoader and Class.forName

OSGi Classloader cant find class ClassNotFoundException

Why is the result inconsistent for loading a file from class vs. the classloader

Why is this lambda function initiating class loading in the wrong classloader?

Java - Find all the methods returning a specific type from classloader

Custom ClassLoader with resource loading

Resource loading using ClassLoader

Loading an array with a classloader

Loading files with ClassLoader

Class.forName() vs ClassLoader.loadClass() - which to use for dynamic loading?

Custom classloader loading a jar gives me an Illegal UTF8 string in constant pool in class file

jQuery - Find specific class and remove it

Find elements with specific class name

Jquery Find a specific class with a specific attribute value

How to find a specific class that contains another class?

Kafka Java Client: ClassLoader doesn't find SASL/Scram Login Class

get CtClass using specific ClassLoader

get CtClass using specific ClassLoader

Is the defining classloader of a class level annotation always a parent of the initiating classloader of that class?

classloader in java is a class itself then who will load the classloader class?

Using ClassLoader when loading .jar resources

Loading a KeyStore in Java 7 leaks the Classloader

is class locking related to java classloader?

LambdaMetafactory to access class on a different ClassLoader

Create new ClassLoader to reload Class

Find ID of next instance of a specific class

Find next input field of specific class

Find the closest ancestor element that has a specific class