1: getPath() 獲取相對路徑java
String path = clazz.getResource("").getPath(); return new File(path).getAbsolutePath();
2: getRootClassPath()
jsp
String path = PathKit.class.getClassLoader().getResource("").toURI().getPath(); return new File(path).getAbsolutePath();
3.getWebRootPathspa
String path = Class .class.getResource("/").toURI().getPath(); return new File(path).getParentFile().getParentFile().getCanonicalPath();
結果code
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