我使用org.reflections库在包中查找资源:
new Reflections(
"test", //package prefix
new ResourcesScanner()
).getResources(x -> x.endsWith(".xml"))在添加类似名称的包之前,它工作得很好。
例如,它只是包test和添加的包test_second
|
+-+-[test]
| +--one.xml
| +--two.xml
|
+-+-[test_second]
+--three.xml
+--four.xml现在,当我试图通过前缀扫描它时,两个包的资源都被找到了。
问题:如何使用这个库只扫描"test“包中的资源,而忽略所有带有"test”前缀的包?
发布于 2022-03-30 20:55:12
我知道,现在有点晚了,但是您必须在包前缀的末尾添加一个.:"test."。我们使用它有点不同,但解决了与您所遇到的问题完全相同的问题:
String location = "test.";
Collection<URL> urls = ClasspathHelper.forPackage(location);
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new ResourcesScanner())
.filterInputsBy(new FilterBuilder().includePackage(location))
.setUrls(urls));
Set<String> resources = reflections.getResources(x -> x.endsWith(".xml"));注意:这个示例正在使用0.9.x。目前,我正致力于将这个迁移到0.10.x。
https://stackoverflow.com/questions/46162522
复制相似问题