ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration 无法转换为 org.apache.xerces.xni.parser.XMLParserConfiguration [英] ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration

查看:15
本文介绍了ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration 无法转换为 org.apache.xerces.xni.parser.XMLParserConfiguration的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Eclipse 中开发 GWT 应用程序并使用 jdom2 读取一些自定义 xml 属性文件.

I am developing a GWT application in Eclipse and use jdom2 to read some custom xml property files.

在最近更新之后,我的应用程序现在在尝试读取 xml 文件时失败并出现上述错误.相关的堆栈跟踪是:

Following a recent update my application now fails with the above error when trying to read the xml file. The relevant stack trace is:

org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration
org.apache.xerces.parsers.SAXParser.<init>(Unknown Source)
org.apache.xerces.parsers.SAXParser.<init>(Unknown Source)
org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.<init>(Unknown Source)
org.apache.xerces.jaxp.SAXParserImpl.<init>(Unknown Source)
org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParser(Unknown Source)
org.jdom2.input.sax.XMLReaders.createXMLReader(XMLReaders.java:165)
org.jdom2.input.SAXBuilder.createParser(SAXBuilder.java:871)
org.jdom2.input.SAXBuilder.buildEngine(SAXBuilder.java:854)
org.jdom2.input.SAXBuilder.getEngine(SAXBuilder.java:904)
org.jdom2.input.SAXBuilder.build(SAXBuilder.java:1116)
uk.co.platosys.db.jdbc.DatabaseProperties.loadProperties(DatabaseProperties.java:78)

对此问题的研究表明,当类路径上存在不兼容的 xerces jar 版本时,可能会出现错误.

Researching this problem suggests that the error can arise when incompatible versions of the xerces jars exist on the classpath.

gwt-dev-2.6.1.jar 包含 xerces 包,我的预感是这个最新版本的 gwt-dev 捆绑了一个不兼容的版本.然而,当前版本 jdom2.0.5 与 2.11 版本的 Xerces 一起发布,这似乎是 Apache 发布的最新版本.将这些 jars 放在我的类路径上似乎并不能解决问题;我以前能够依赖 gwt-dev 中的版本.

gwt-dev-2.6.1.jar contains the xerces packages and my hunch is that this latest version of gwt-dev has bundled a version that is incompatible. However jdom2.0.5, the current release, is released with the 2.11 version of Xerces which seems to be the latest released by Apache. Putting these jars on my classpath doesn't seem to resolve matters; I have previously been able to rely on the versions in gwt-dev.

我对此相当不知所措,并且大大超出了我的舒适区.

I am rather at my wits' end about this and considerably out of my comfort zone.

推荐答案

当我将我的项目从 GWT 2.7 升级到 GWT 2.8 时,我遇到了同样的异常.我不知道为什么我在 GWT 2.7 中没有这个问题(可能 Eclipse 项目的 .classpath 文件中的不同位置会影响它).

I had a same exception when I upgraded my project from GWT 2.7 to GWT 2.8. I have no idea why I had not this problem with GWT 2.7 (maybe different position of in .classpath file of Eclipse project could affect it).

那个异常的原因是之前有这样的代码:

The reason for that exception was that before with such code like:

DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance();
DocumentBuilder newDocumentBuilder = newInstance.newDocumentBuilder();
baseLayoutXmlDocument = newDocumentBuilder.parse( baseLayoutSvgInputStream );

SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();

使用了来自 JDK 包 com.sun.org.apache.xerces.internal.jaxp 的实现,但在升级到 GWT2.8 后,我的应用程序选择了来自 gwt-dev.jar 的 xerces.我根据 Javadoc 和 链接在这里使用系统属性

the implementations from JDK package com.sun.org.apache.xerces.internal.jaxp was used, but after upgrade to GWT2.8 my app chose the xerces from gwt-dev.jar. I found the fix for that according to Javadoc and link here to used system properties

-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl

这篇关于ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration 无法转换为 org.apache.xerces.xni.parser.XMLParserConfiguration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆