获取部署的路径
String ProjectPath=XXX.class.getProtectionDomain().getCodeSource().getLocation().getPath();
这个比其他的都好用
public static String getCurrentPath(Class<?> cls) {
String path = cls.getProtectionDomain().getCodeSource().getLocation().getPath();
path = path.replaceFirst("file:/", "");
path = path.replaceAll("!/", "");
if(path.lastIndexOf(File.separator) >= 0) {
path = path.substring(0, path.lastIndexOf(File.separator));
}
if(path.substring(0, 1).equalsIgnoreCase("/")) {
String osName = System.getProperty("os.name").toLowerCase();
if(osName.indexOf("window") >= 0) {
path = path.substring(1);
}
}
return path;
}