场景如下:在我的项目根路径下有几个外部程序、脚本,我需要在开发环境获取项目的根目录,如我的项目名为project-a,此时获取的是xxx/project-a/
打成jar包后是jar包所在目录的父路径,也是xxx/project-a/
有没有什么简单的方法呢?自己这个还是感觉有点缺陷
public static String getAppRootPath(){
String activeProfile = SpringUtil.getActiveProfile();
if ("prod".equals(activeProfile)){
return XXXApplication.class.getProtectionDomain().getCodeSource().getLocation().getPath();
}else {
return System.getProperty("user.dir");
}
}