0

使用Reflections 库,如何在一个包中获取具有特定文件扩展名的所有资源?

我试过这段代码:

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setUrls(...);
    cb.setScanners(new ResourcesScanner());
    FilterBuilder fb = new FilterBuilder();
    fb.include(FilterBuilder.prefix("org.p1")); //filtering resources in package "org.p1"
    cb.filterInputsBy(fb);
    Reflections reflections = new Reflections(cb);
    Pattern pattern = Pattern.compile(".*\\.xxx");
    Set<String> set = reflections.getResources(pattern); //resources having as extension "xxx" and located in package "org.p1"

但这是回答包“org.p1”其中的任何子包(例如“org.p1.p2”)中扩展名为“xxx”的所有资源。

我可以将反射配置为仅回答位于“org.p1”中的资源并忽略其子包(如果有)吗?

4

1 回答 1

0

为什么不试试Pattern.compile("org\\.p1\\.xxx");呢?

于 2012-11-26T18:29:13.583 回答