Find where java class is loaded from

前端 未结 11 1284
独厮守ぢ
独厮守ぢ 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条回答
  •  -上瘾入骨i
    2020-11-22 06:38

    Simple way:

    System.out.println(java.lang.String.class.getResource(String.class.getSimpleName()+".class"));

    Out Example:

    jar:file:/D:/Java/jdk1.8/jre/lib/rt.jar!/java/lang/String.class

    Or

    String obj = "simple test"; System.out.println(obj.getClass().getResource(obj.getClass().getSimpleName()+".class"));

    Out Example:

    jar:file:/D:/Java/jdk1.8/jre/lib/rt.jar!/java/lang/String.class

提交回复
热议问题