最近的一个程序,是非web项目,仅仅使用到了jfinal的DB+Record和Enjoy,开发完后,本地测试都通过,但是用maven插件打成jar包,在linux上跑的时候,发现PathKit.getRootClassPath()空指针。后波总修改PathKit代码如下:
public static String getRootPath() {
String rootClassPath = "";
try {
String path = getClassLoader().getResource("").toURI().getPath();
rootClassPath = new File(path).getAbsolutePath();
}
catch (Exception e) {
try {
String path = PathUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath();
path = java.net.URLDecoder.decode(path, "UTF-8");
if (path.endsWith(File.separator)) {
path = path.substring(0, path.length() - 1);
}
rootClassPath = path;
} catch (UnsupportedEncodingException e1) {
throw new RuntimeException(e1);
}
}
return rootClassPath;
}
private static ClassLoader getClassLoader() {
ClassLoader ret = Thread.currentThread().getContextClassLoader();
return ret != null ? ret : PathUtils.class.getClassLoader();
}完美解决!