ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration

前端 未结 7 900
我寻月下人不归
我寻月下人不归 2020-12-10 15:02

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

Following a recent update my application now fails with the above

相关标签:
7条回答
  • 2020-12-10 15:03

    In my case I resolved this issue by adding to bootstrap entities (Classpath tab in run configuration) two entries /xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar and /xerces/xercesImpl/2.11.0/xercesImpl-2.11.0.jar from my local maven repository

    0 讨论(0)
  • 2020-12-10 15:03

    The order of the jars on the classpath matters. Did you try adding the Xerces 2.11 jar at the beginning of the classpath so it gets loaded first?

    0 讨论(0)
  • 2020-12-10 15:06

    Don't fight with Maven: if things aren't used together, they should go in separate maven modules. In your case, JDom is (probably) used on the server-side, which doesn't need gwt-dev. So the solution is to split your project into several Maven modules: one for the client-side that depends on GWT, and one for the server-side that doesn't (or possibly on gwt-servlet if you use GWT-RPC, or on requestfactory-server if you use RequestFactory).

    That said, even with a single project, if you do have gwt-dev in your classpath at runtime, then you got something wrong in your POM.

    …unless you're reading your XML files at build-time?

    0 讨论(0)
  • 2020-12-10 15:06

    In my case this was resolved by deleting the xerces directory in my local sbt cache (local maven repository if you use maven), and rebuilding the project.

    0 讨论(0)
  • 2020-12-10 15:23

    This is a bit late, but after reading through the answers I did find one way to work around this problem. Instead of building your document factory with the normal DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); you could use the parameters in newInstance to specifically choose. This way you don't have to add JVM parameters like Svarog's answer above, and you don't have to add or remove libraries. My solution is as follows:

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", this.getClass().getClassLoader());
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new FileInputStream("path/to/file.xml"));
    
    0 讨论(0)
  • 2020-12-10 15:26

    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();
    

    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
    
    0 讨论(0)
提交回复
热议问题