Skip to content
Browse files

fix issue #198

  • Loading branch information...
1 parent b3789f6 commit 33318dcd0fba09aa48d773964c4f895f312958b1 @wendal wendal committed Apr 20, 2012
View
30 src/org/nutz/resource/impl/AbstractResourceScan.java
@@ -17,6 +17,7 @@
import org.nutz.lang.util.FileVisitor;
import org.nutz.log.Log;
import org.nutz.log.Logs;
+import org.nutz.resource.JarEntryInfo;
import org.nutz.resource.NutResource;
import org.nutz.resource.ResourceScan;
import org.nutz.resource.Scans;
@@ -119,15 +120,24 @@ protected static String checkSrc(String src) {
}
protected void scanClasspath(String src, Pattern regex, List<NutResource> list) {
- String classpath = System.getProperties().getProperty("java.class.path");
- if (log.isInfoEnabled())
- log.info("Try to search in classpath : " + classpath);
- String[] paths = classpath.split(System.getProperties().getProperty("path.separator"));
- for (String pathZ : paths) {
- if (pathZ.endsWith(".jar"))
- list.addAll(scanInJar(checkSrc(src), regex, pathZ));
- else
- list.addAll(scanInDir(regex, new File(pathZ + "/" + src), true));
- }
+ try {
+ String classpath = System.getProperties().getProperty("java.class.path");
+ if (log.isInfoEnabled())
+ log.info("Try to search in classpath : " + classpath);
+ String[] paths = classpath.split(System.getProperties().getProperty("path.separator"));
+ for (String pathZ : paths) {
+ if (pathZ.endsWith(".jar"))
+ list.addAll(scanInJar(checkSrc(src), regex, pathZ));
+ else
+ list.addAll(scanInDir(regex, new File(pathZ + "/" + src), true));
+ }
+ } catch (Throwable e) {}
+ //这是最后的手段了
+ try {
+ Enumeration<URL> urls = getClass().getClassLoader().getResources("/META-INF/MANIFEST.MF");
+ while (urls.hasMoreElements()) {
+ list.addAll(scanInJar(src, regex, new JarEntryInfo(urls.nextElement().toString()).getJarPath()));
+ }
+ } catch (Throwable e) {}
}
}
View
3 src/org/nutz/resource/impl/LocalResourceScan.java
@@ -105,8 +105,7 @@ public LocalResourceScan(boolean ignoreHidden) {
}
}
}
- if (list.isEmpty())
- scanClasspath(src, regex, list);
+ scanClasspath(src, regex, list);
// 返回资源列表
return list;
}

0 comments on commit 33318dc

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