Find where java class is loaded from

前端 未结 11 1394
独厮守ぢ
独厮守ぢ 2020-11-22 06:22

Does anyone know how to programmaticly find out where the java classloader actually loads the class from?

I often work on large projects where the classpath gets v

11条回答
  •  执笔经年
    2020-11-22 06:54

    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
    

提交回复
热议问题