浏览代码

拷贝静态文件2

chao 4 年之前
父节点
当前提交
99a67a02dc
共有 2 个文件被更改,包括 6 次插入9 次删除
  1. 6 9
      src/main/java/com/caimei/www/service/generate/impl/GenerateHtmlImpl.java
  2. 二进制
      target/www-0.0.1-SNAPSHOT.jar

+ 6 - 9
src/main/java/com/caimei/www/service/generate/impl/GenerateHtmlImpl.java

@@ -103,7 +103,7 @@ public class GenerateHtmlImpl implements GenerateHtml {
         try {
             copyResourceToFile();
             return "[静态页服务]:拷贝静态资源文件成功! ^_^";
-        } catch (IOException e) {
+        } catch (Exception e) {
             log.error("[静态页服务]:拷贝静态资源文件异常!", e);
             return "[静态页服务]:拷贝静态资源文件异常!"+e.toString();
         }
@@ -176,16 +176,13 @@ public class GenerateHtmlImpl implements GenerateHtml {
                 }
                 //分析相对目录
                 String tempPath = "";
-                String pathFlag = "/static/";
-                String sUrl = resource.getURL().toString();
-                if (sUrl.startsWith("file:")) {
-                    tempPath = sUrl.substring("file:".length() - 1);
-                }
-                int rootPathIndex = tempPath.indexOf(pathFlag);
-                if (rootPathIndex < 0) {
+                String[] urls = resource.getURL().toString().split("/static/");
+                if (urls.length >= 2 ){
+                    tempPath = urls[urls.length-1];
+                } else {
                     throw new RuntimeException("relativeRootPath有误:无法分析相对目录");
                 }
-                tempPath = tempPath.substring(rootPathIndex + pathFlag.length(), tempPath.length() - fileName.length());
+                tempPath = tempPath.substring(0, tempPath.length() - fileName.length());
                 if (StringUtils.isEmpty(tempPath)) {
                     tempPath = File.separator;
                 }

二进制
target/www-0.0.1-SNAPSHOT.jar