我有一个 war 结构: 一些.war
-WEB-INF
--lib
---图书馆.jar
----some.xsd
----some2.xsd
而且我想获取 library.jar 中的所有 xsd 文件,但 spring 不想搜索它。
ContextLoaderListener.getCurrentWebApplicationContext()
.getResources("classpath*:**/*.xsd")
结果为空。我也试过:classpath:**/*.xsd
, **/*.xsd
.
如何使用“ant”模板 (*/.xsd) 获取 jar 中的所有 xsd 文件?
最佳答案
答案就在 Spring 文档中:
4.7.2.3 Other notes relating to wildcards
Please note that "classpath*:" when combined with Ant-style patterns will only work reliably with at least one root directory before the pattern starts, unless the actual target files reside in the file system. This means that a pattern like "classpath*:*.xml" will not retrieve files from the root of jar files but rather only from the root of expanded directories. This originates from a limitation in the JDK's
ClassLoader.getResources()
method which only returns file system locations for a passed-in empty string (indicating potential roots to search).
关于java - Spring:在内部 jar 中搜索资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6074411/