Skip to content
This repository
Browse code

fix issue #198

  • Loading branch information...
commit 33318dcd0fba09aa48d773964c4f895f312958b1 1 parent b3789f6
Wendal Chen wendal authored
30 src/org/nutz/resource/impl/AbstractResourceScan.java
@@ -17,6 +17,7 @@
17 17 import org.nutz.lang.util.FileVisitor;
18 18 import org.nutz.log.Log;
19 19 import org.nutz.log.Logs;
  20 +import org.nutz.resource.JarEntryInfo;
20 21 import org.nutz.resource.NutResource;
21 22 import org.nutz.resource.ResourceScan;
22 23 import org.nutz.resource.Scans;
@@ -119,15 +120,24 @@ protected static String checkSrc(String src) {
119 120 }
120 121
121 122 protected void scanClasspath(String src, Pattern regex, List<NutResource> list) {
122   - String classpath = System.getProperties().getProperty("java.class.path");
123   - if (log.isInfoEnabled())
124   - log.info("Try to search in classpath : " + classpath);
125   - String[] paths = classpath.split(System.getProperties().getProperty("path.separator"));
126   - for (String pathZ : paths) {
127   - if (pathZ.endsWith(".jar"))
128   - list.addAll(scanInJar(checkSrc(src), regex, pathZ));
129   - else
130   - list.addAll(scanInDir(regex, new File(pathZ + "/" + src), true));
131   - }
  123 + try {
  124 + String classpath = System.getProperties().getProperty("java.class.path");
  125 + if (log.isInfoEnabled())
  126 + log.info("Try to search in classpath : " + classpath);
  127 + String[] paths = classpath.split(System.getProperties().getProperty("path.separator"));
  128 + for (String pathZ : paths) {
  129 + if (pathZ.endsWith(".jar"))
  130 + list.addAll(scanInJar(checkSrc(src), regex, pathZ));
  131 + else
  132 + list.addAll(scanInDir(regex, new File(pathZ + "/" + src), true));
  133 + }
  134 + } catch (Throwable e) {}
  135 + //这是最后的手段了
  136 + try {
  137 + Enumeration<URL> urls = getClass().getClassLoader().getResources("/META-INF/MANIFEST.MF");
  138 + while (urls.hasMoreElements()) {
  139 + list.addAll(scanInJar(src, regex, new JarEntryInfo(urls.nextElement().toString()).getJarPath()));
  140 + }
  141 + } catch (Throwable e) {}
132 142 }
133 143 }
3  src/org/nutz/resource/impl/LocalResourceScan.java
@@ -105,8 +105,7 @@ public LocalResourceScan(boolean ignoreHidden) {
105 105 }
106 106 }
107 107 }
108   - if (list.isEmpty())
109   - scanClasspath(src, regex, list);
  108 + scanClasspath(src, regex, list);
110 109 // 返回资源列表
111 110 return list;
112 111 }

0 comments on commit 33318dc

Please sign in to comment.
Something went wrong with that request. Please try again.