String path = Test.class.getProtectionDomain().getCodeSource().getLocation().getFile();
这个是得到类所在jar包的实际路径,也就是说,该类是作为项目的依赖jar包中的类。
Test.class.getClass().getResource(".").getPath();
Test.class.getClassLoader().getResource("").getPath();
String path = Test.class.getProtectionDomain().getCodeSource().getLocation().getFile();
这个是得到类所在jar包的实际路径,也就是说,该类是作为项目的依赖jar包中的类。
Test.class.getClass().getResource(".").getPath();
Test.class.getClassLoader().getResource("").getPath();