How would you go about establishing where a class ( or maybe resource ) has been loaded from?
I am trying to work out exactly where a class has been loaded from. Does anyone know if you can find out the following:
The class Class
has an instance method getClassLoader()
that returns a reference to the class loader that loaded the class it represents. Note that this can return null
. See here.
So, if you wanted to know which classloader loaded String
(just as an example) you could do:
ClassLoader loader = String.class.getClassLoader();
or:
ClassLoader loader = "I'm a String".getClass().getClassLoader();
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