(1) 本地Windows测试环境
//获取到当前项目的上一级目录
public static String getProjParentPath(){
String projPath = System.getProperties().getProperty("user.dir");
return new File(projPath).getParent();
}
(2) jar包部署到Ubuntu/Linux环境
//获取到当前项目所在路径
public static String getProjPath(){
return System.getProperties().getProperty("user.dir");
}
这篇博客介绍了如何在Java中获取本地Windows测试环境与Ubuntu/Linux部署环境下的项目路径。通过`System.getProperties().getProperty(user.dir)`方法,可以得到当前工作目录。在Windows环境下获取的是上一级目录,而在Linux环境下则是当前项目路径。
481

被折叠的 条评论
为什么被折叠?



