版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011119684/article/details/78719651
String jarWholePath = MyClass.class.getProtectionDomain().getCodeSource().getLocation().getFile();
try {
jarWholePath = java.net.URLDecoder.decode(jarWholePath, "UTF-8");
} catch (UnsupportedEncodingException e) { System.out.println(e.toString()); }
try {
jarWholePath = java.net.URLDecoder.decode(jarWholePath, "UTF-8");
} catch (UnsupportedEncodingException e) { System.out.println(e.toString()); }
String jarPath = new File(jarWholePath).getParentFile().getAbsolutePath();