不起作用这里的情景:十一:包括JAR文件中的XML文件中WildFly
我捆绑几个.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
文件的正确组合是什么?
编辑:这里的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
)。
什么是你的使用情况?真的有必要将您的设置打包到jar文件中吗? – 2017-04-21 20:57:39
http://stackoverflow.com/questions/8412798/how-to-load-xmlcatalog-from-classpath-resources-inside-a-jar-reliably 看看是否有帮助 – 2017-04-22 06:10:51
你可以显示你用于创建的代码解析器/映射器? – ctomc