Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring: search resources in inner jar

I have a this war structure: Some.war

-WEB-INF
--lib
---library.jar
----some.xsd
----some2.xsd

And 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 files in jar using "ant" template (*/.xsd)?

like image 897
Alexey Kutuzov Avatar asked Feb 25 '23 03:02

Alexey Kutuzov


1 Answers

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).

like image 125
Sean Patrick Floyd Avatar answered Feb 26 '23 22:02

Sean Patrick Floyd