使用Reflections库查询给定包中的资源,忽略子包

时间:2012-11-26 18:19:42

标签: java google-reflections

使用Reflections library,如何获取具有完全位于一个包中的特定文件扩展名的所有资源?

我尝试使用此代码:

    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” AND 包中的扩展名“xxx”的所有资源(例如,“org.p1.p2”)。

我可以配置Reflection只回答“org.p1”中的资源并忽略其子包(如果有的话)吗?

1 个答案:

答案 0 :(得分:0)

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

相关问题