ClassCastException while parsing XML with WebLogic
Asked Answered
P

7

17

I'm getting the following error message:

java.lang.ClassCastException: weblogic.xml.jaxp.RegistryDocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory

I've gone through some forums researching this. They said to remove xml-apis.jar or that JAR files were conflicting. But even though I did all the suggested steps, I'm getting the same error.

Paracelsus answered 7/2, 2011 at 20:1 Comment(4)
Check out sotretus answer in this thread. It might be applicable to you if you're using Maven2. forum.springsource.org/archive/index.php/t-22597.htmlSalzhauer
Have you verified that there is no jar left in WEB-INF/lib?Variorum
I have all jars into the WEB-INF/lib folder.But getting this error...Paracelsus
[dealing with xerces hell in java maven][1] [1]: #11678072Jaquith
H
14

It's always the xml-apis.jar. Remove them from your classpath (e.g. remove them from WEB-INF/lib of your webapp).

Handrail answered 7/2, 2011 at 21:28 Comment(0)
A
5

Remove xml-beans-1.xb2 to the lib directory. Modified the POM so it does not include that jar file with the following:

<dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.0.b2</version>
    <scope>provided</scope>
</dependency>
Atomizer answered 25/6, 2014 at 7:49 Comment(0)
O
4

I think Banang is right. Forum http://forum.springsource.org/showthread.php?t=22597 describes solution for similar problem.

Typically such problems happen when there are several versions of the same class in class path while those versions are loaded by different class loaders. One version of DocumentBuilderFactory was loaded by system class loader, other by class loader of your enterprise application. When you are calling the XML parser the parent's version of the class is used. When you are casting yours private version is utilized. These versions are incompatible that causes ClassCastException.

Ostracoderm answered 7/2, 2011 at 21:20 Comment(0)
D
4

The reason for this issue is you are having multiple jars with same class name in library. Go to WEB-INF/lib and remove xml-apis-1.0.b2.jar and stax-api-1.0.1.jar or remove them from you pom.xml itself and you would be good to go.

Demonology answered 7/2, 2014 at 21:49 Comment(0)
S
2

I wanted make a slight addition to the previous answers to this question, in the event that anyone else is in the same situation I was. I had the same problem on our WebLogic 9.2 server due to my use of CXF 2.2.3. In addition to the removal of the xml-apis.jar mentioned previously, I also had to remove a xmlParserAPIs library.

As I am using Maven2 it was just a simple matter of adding another inclusion.

    <!-- CXF -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-bundle</artifactId>
        <version>${dependency.version.cxf}</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>xml-apis</artifactId>
                <groupId>xml-apis</groupId>
            </exclusion>
            <exclusion>
                <artifactId>xercesImpl</artifactId>
                <groupId>xerces</groupId>
            </exclusion>
            <exclusion>
                <artifactId>xmlbeans</artifactId>
                <groupId>org.apache.xmlbeans</groupId>
            </exclusion>
            <exclusion>
                <artifactId>xmlParserAPIs</artifactId>
                <groupId>xerces</groupId>
            </exclusion>
        </exclusions>
    </dependency>

Hope this helps someone!

Swansea answered 25/5, 2011 at 17:41 Comment(2)
Thanks. although my setup only needed the xml-apis exclusion.Catchfly
In my case I had to use this full exclusion package, thanks!Lingcod
F
1

We also has such trouble. The reason of error was in gwt library. Receipe: exlude all gwt client libraries from distr.

Fungus answered 28/5, 2013 at 4:59 Comment(0)
S
0

As for my case, I managed to solve this issue by removing xml-apis library and also upgrading an XML processing library:

From org.apache.xmlbeans/xmlbeans/2.4.0

Into org.apache.xmlbeans/xmlbeans/2.6.0

FYI, I'm using Weblogic 10.3.6.0.

Subtractive answered 25/5, 2016 at 3:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.