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?
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.
clazz.getProtectionDomain().getCodeSource().getLocation()
Obvious! (May NPE.)
(ClassLoader
s can load classes from multiple locations.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With