Find where java class is loaded from

前端 未结 11 1272
独厮守ぢ
独厮守ぢ 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:35

    Edit just 1st line: Main.class

    Class c = Main.class;
    String path = c.getResource(c.getSimpleName() + ".class").getPath().replace(c.getSimpleName() + ".class", "");
    
    System.out.println(path);
    

    Output:

    /C:/Users/Test/bin/
    

    Maybe bad style but works fine!

提交回复
热议问题