我正在尝试使用以下方法查找正在运行的jar文件的位置:
File jarFile = new File(JarPath.class.getProtectionDomain().getCodeSource().getLocation().toURI());
Run Code Online (Sandbox Code Playgroud)
当我在IDE(eclipse)上运行它时,它返回正确的路径.但是当我将jar作为可执行文件运行时,返回的代码源是
rsrc:./
Run Code Online (Sandbox Code Playgroud)
关于如何获得正确路径的想法?