ソースを参照

改进 detectWebRootPath(),maven 项目在开发环境下探测到 webRootPath

James 4 年 前
コミット
33932d892a
1 ファイル変更9 行追加1 行削除
  1. 9 1
      src/main/java/com/jfinal/kit/PathKit.java

+ 9 - 1
src/main/java/com/jfinal/kit/PathKit.java

@@ -123,7 +123,15 @@ public class PathKit {
 	private static String detectWebRootPath() {
 		try {
 			String path = PathKit.class.getResource("/").toURI().getPath();
-			return new File(path).getParentFile().getParentFile().getCanonicalPath();
+			String ret = new File(path).getParentFile().getParentFile().getCanonicalPath();
+			// 支持 maven 项目在开发环境下探测 webRootPath
+			if (path.endsWith("/target/classes/")) {
+				return ret + "/src/main/webapp";
+			} else if (path.endsWith("\\target\\classes\\")) {
+				return ret + "\\src\\main\\webapp";
+			} else {
+				return ret;
+			}
 		} catch (Exception e) {
 			throw new RuntimeException(e);
 		}