Find where java class is loaded from Find where java class is loaded from java java

Find where java class is loaded from


Here's an example:

package foo;public class Test{    public static void main(String[] args)    {        ClassLoader loader = Test.class.getClassLoader();        System.out.println(loader.getResource("foo/Test.class"));    }}

This printed out:

file:/C:/Users/Jon/Test/foo/Test.class


Another way to find out where a class is loaded from (without manipulating the source) is to start the Java VM with the option: -verbose:class


getClass().getProtectionDomain().getCodeSource().getLocation();