作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
场景如下:
我将我的应用程序运行所需的几个 .xml
(某种配置)文件捆绑在一个 .jar
文件中。 jar 文件具有以下结构:
settings-1.0.0.jar
˪ resources/
˪ 1.xml
˪ 2.xml
˪ 3.xml
˪ META-INF/
˪ MANIFEST.MF
1.xml
包含以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
<!-- Include 2 -->
<xi:include
href="resource:resources/2.xml" />
<!-- Include 3 -->
<xi:include
href="resource:resources/3.xml" />
<!--
<map>
</map>
-->
</document>
基于 this文章。尝试访问这些包含时(成功部署我的应用程序后)我收到以下错误:
Caused by: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 43; An 'include' failed, and no 'fallback' element was found.
at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:245)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:298)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
at org.zcore.dkp.backend.mapper.MappingParser.parse(MappingParser.java:60)
... 327 more
我尝试了(错误)了所有可以想到的选项。 xi:include
将 .xml
文件放入作为 WildFly 模块安装的 jar
文件的正确组合是什么?
编辑:这是加载 xml 文件的方式:
private void loadBackendMapping() {
try {
BackendMappingParser parser = new BackendMappingParser();
InputStream in = ResourceLoaderHelper.getResourceAsStream(BACKEND_MAPPING_RESOURCE);
if (in == null) {
throw new FileNotFoundException();
}
try {
parser.parse(in);
} finally {
try {
in.close();
} catch (IOException e) {
log.warn("Failed to close " + BACKEND_MAPPING_RESOURCE, e);
}
}
backendMapping = parser.getMapping();
if (log.isDebugEnabled()) {
log.debug(BACKEND_MAPPING_RESOURCE + " successfully loaded!");
}
} catch (FileNotFoundException e) {
log.warn("\"" + BACKEND_MAPPING_RESOURCE + "\" not found!");
backendMapping = new BackendMapping();
} catch (Exception e) {
throw new CenterwareSystemException("Failed to parse " + BACKEND_MAPPING_RESOURCE, e);
}
}
BACKEND_MAPPING_RESOURCE
包含文件名 (1.xml
)。
最佳答案
这取决于您的 XML 解析器。
根据您的异常(exception)情况,您似乎使用了 SAX。
试试这篇文章: https://www.ibm.com/developerworks/library/x-tipentres/
上述文档使用 SAX API 的 EntityResolver
接口(interface)在 XML 文档中定位资源。
关于java - 习 :include in xml file within jar file does not work in WildFly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43391212/
场景如下: 我将我的应用程序运行所需的几个 .xml(某种配置)文件捆绑在一个 .jar 文件中。 jar 文件具有以下结构: settings-1.0.0.jar ˪ resources/ ˪
我是一名优秀的程序员,十分优秀!