gpt4 book ai didi

java - 习 :include in xml file within jar file does not work in WildFly

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:24:11 26 4
gpt4 key购买 nike

场景如下:

我将我的应用程序运行所需的几个 .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 APIEntityResolver 接口(interface)在 XML 文档中定位资源。

关于java - 习 :include in xml file within jar file does not work in WildFly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43391212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com