- 该方法可以获取项目在服务器上运行的路径,也可以回去在开发时路径
public String getPath() {
String path = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
if (System.getProperty("os.name").contains("dows")) {
path = path.substring(1);
}
if (path.contains("jar")) {
path = path.substring(0, path.lastIndexOf("."));
return path.substring(0, path.lastIndexOf("/"));
}
return path.replace("/target/classes/", "");
}