/**
* 获得工程的classpath根目录
* @return String
*/
public String getClasspath() {
try {
return Class.forName("随便一个class").getResource("/").getPath();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
/**
* 获得工程的WebRoot根目录
* @return String
*/
public String getWebRootPath() {
try {
String classpath = getClasspath();// classes 目录的物理路径
String webInfoPath = new File(classpath).getParent();// WEB-INF 目录的物理路径
return new File(webInfoPath).getParent();// WebRoot 目录的物理路径
} catch (Exception e) {
e.printStackTrace();
}
return "";
}