查找与模式匹配的所有CLASSPATH资源 [英] Finding all CLASSPATH resources matching a pattern

查看:145
本文介绍了查找与模式匹配的所有CLASSPATH资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用上下文类加载器将它们作为资源加载来阅读一堆文本文件。

I want to read a bunch of text files, by loading them as resources using the context classloader.

URL url = Thread.currentThread()
                .getContextClassLoader()
                .getResource("folder/foo.txt");

有没有办法获得名称与给定模式匹配的资源列表?例如:

Is there some way to get a list of resources whose names match a given pattern? For eg:

URL[] matchingUrls = someLibrary.getMatchingResources("folder/*.txt");

像Spring这样的库可以扫描类路径来查找带有给定注释的类,所以我想知道是否存在类似于加载一堆资源的东西。

Libraries like Spring can scan the classpath to find classes with a given annotation, so I am wondering if there something similar to load a bunch of resources.

推荐答案

Spring支持ant风格的类路径资源匹配。

Spring supports ant-style class path resource matching.

http:// static。 springsource.org/spring/docs/2.5.x/reference/resources.html

例如: classpath:com / mycompany /**/applicationContext.xml,/ WEB-INF / * - context.xml

查看是否可以将spring用于项目。如果不可能那么你可以随时下拉源代码来看看他们在做什么,并自己做:)

See if you can use spring for your project. If it is not possible then you can always pull down the source code to see what they are doing, and do that yourself :)

这篇关于查找与模式匹配的所有CLASSPATH资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆