Custom Scanner
实施自己的扫描仪。例如:
private List<String> getResourceFiles(String path) throws IOException { List<String> filenames = new ArrayList<>(); try ( InputStream in = getResourceAsStream(path); BufferedReader br = new BufferedReader(new InputStreamReader(in))) String resource; while ((resource = br.readLine()) != null) { filenames.add(resource); } } return filenames;}private InputStream getResourceAsStream(String resource) { final InputStream in = getContextClassLoader().getResourceAsStream(resource); return in == null ? getClass().getResourceAsStream(resource) : in;}private ClassLoader getContextClassLoader() { return Thread.currentThread().getContextClassLoader();}
Spring framework
PathMatchingResourcePatternResolver从Spring framework使用。
Ronmamo Reflections
对于巨大的CLASSPATH值,其他技术在运行时可能很慢。更快的解决方案是使用ronmamo的Reflections API,该API在编译时对搜索进行预编译。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)