java - Spring:在内部 jar 中搜索资源

标签 java spring resources

我有一个 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/

相关文章:

java - Spring 和 Angular2 400(错误请求)

java - GWT 复合小部件

java - 没有 for 循环会在 for 循环内部运行。素数测试

mysql - Spring 数据休息: What should be the return type of Query

oracle - 数据库对象代码生成的资源

java - 如何在程序生成的地牢中找到房间中的门数量?

java - 使用mockito在函数中存在具有setter getter方法的模拟类对象

java - 创建一个 Spring bean 保存 ServletRequest 属性

c++ - 在 native Windows 应用程序的资源中嵌入文本文件

java - 从资源中读取 XML 文件