xi:包含在jar文件内的xml文件在WildFly中不起作用

以下是该场景:

我捆绑了我的应用程序在.jar文件中运行所需的几个.xml (某些配置文件)。 该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>

基于这篇文章。 当试图访问这些包括(成功部署我的应用程序后),我得到以下错误:

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的正确组合xi:include在安装为WildFly模块的jar文件中xi:include一个.xml文件?

编辑:这是如何加载xmlfile:

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解析器。

根据你的例外,你似乎使用SAX。
试试这篇文章:https://www.ibm.com/developerworks/library/x-tipentres/

上述文档使用SAX APIEntityResolver接口来定位XML文档中的资源。


从你的URL中删除“resource:”前缀,因为这似乎是一个JBoss特定的协议。

还会发出“资源/”路径,因为1.xml,2.xml和3.xml都位于同一个文件夹中,并且通常指定相对路径(从1到2以及从1到3)。

尝试以下操作:

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
    <!-- Include 2 -->
    <xi:include href="2.xml" />
    <!-- Include 3 -->
    <xi:include href="3.xml" />
    <!--
    <map>
    </map>
    -->
</document>
链接地址: http://www.djcxy.com/p/39145.html

上一篇: xi:include in xml file within jar file does not work in WildFly

下一篇: Why dont my facebook interstitial ads show in my app?