Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassCastException while parsing XML with WebLogic

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.

like image 870
rose Avatar asked Feb 07 '11 20:02

rose


5 Answers

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

like image 64
mhaller Avatar answered Nov 13 '22 13:11

mhaller


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>
like image 44
Subhrajyoti Majumder Avatar answered Nov 13 '22 12:11

Subhrajyoti Majumder


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.

like image 41
AlexR Avatar answered Nov 13 '22 13:11

AlexR


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.

like image 4
kumarsparkz Avatar answered Nov 13 '22 13:11

kumarsparkz


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!

like image 2
CatsAndCode Avatar answered Nov 13 '22 13:11

CatsAndCode