使用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”中的资源并忽略其子包(如果有)吗?