【发布时间】:2017-04-13 11:34:36
【问题描述】:
这是场景:
我捆绑了几个.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
我尝试了(&error'd)所有可以想到的选项。在作为 WildFly 模块安装的 jar 文件中,xi:include 的正确组合是什么?
编辑:下面是 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)。
【问题讨论】:
-
您的用例是什么?真的有必要把你的设置打包成一个jar文件吗?
-
你能展示你用来创建解析器/映射器的代码吗?
-
@ctomc 抱歉,没有注意到您的评论。 :-/ 添加了
1.xml是如何以编程方式加载的。
标签: java xml module wildfly xerces