Spring: search resources in inner jar
I have a this war structure: Some.war
-WEB-INF
--lib ---library.jar ----some.xsd ----some2.xsdAnd i want to get all xsd files in library.jar, but spring don't want to search it.
ContextLoaderListener.getCurrentWebApplicationContext()
.getResources("classpath*:**/*.xsd")
result is empty. I also tried: classpath:**/*.xsd
, **/*.xsd
.
How i can get all xsd f开发者_运维百科iles in jar using "ant" template (*/.xsd)?
The answer lies in the Spring docs:
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).
精彩评论