1: getPath() 获取相对路径
String path = clazz.getResource("").getPath();
return new File(path).getAbsolutePath();
2: getRootClassPath()
String path = PathKit.class.getClassLoader().getResource("").toURI().getPath();
return new File(path).getAbsolutePath();
3.getWebRootPath
String path = Class .class.getResource("/").toURI().getPath();
return new File(path).getParentFile().getParentFile().getCanonicalPath();
结果
E:\workspace\jfinal_demo_for_jsp\WebRoot\WEB-INF\classes\com\jfinal\kit
E:\workspace\jfinal_demo_for_jsp\WebRoot\WEB-INF\classes
E:\workspace\jfinal_demo_for_jsp\WebRoot