2

I've just wasted the last days for a strange random exception behaviour in wildfly 10...I've deployed my Java 7 EE .war to the wildfly, but suddenly I got this exception and deployment fail:

java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
goblingift
  • 409
  • 4
  • 19

3 Answers3

6

The solution is: editing the standalone.xml of the wildfly, like adding some spaces and SAVE the file. Then just restart the wildfly and you can deploy your application again...so simple- hope i can help anyone out there.

goblingift
  • 409
  • 4
  • 19
4

In my case same problem was occurring.I am also using wildfly 10 and java 1.8 version. After reading the many solution i discovered this solution from @goblingift comment and his pasted link.

Solution: In pom.xml i simply excluded the dom4j from my hibernate dependency.

<exclusion>
  <groupId>dom4j</groupId>
  <artifactId>dom4j</artifactId>
</exclusion>

As i am using hibernate dependency like this in my pom.xml

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.1.0.Final</version>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
        </exclusion>
        <exclusion>
           <groupId>org.jboss.logging</groupId>
           <artifactId>jboss-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html#Dependency_Exclusions

Bharti Rawat
  • 1,949
  • 21
  • 32
  • This worked for me but my pom.xml was a little different. I added the exclude to each of the dependencies in the pom.xml file that creates my projects .ear file. – John Jun 22 '17 at 14:21
  • Also, there was no reference to a dom4j jar in any of my pom.xml files but when I unzipped the ear file the dom4j.jar was there before I added the exclude. – John Jun 22 '17 at 14:23
  • Rather than excluding, you can try to scope the dom4j dependency as provided. I had to do this rather than excluding because somehow the dom4j dependency was required by other dependencies. – Nis Dec 02 '19 at 15:29
0

The actual problem is you're getting two different org.dom4j.DocumentFactory on your class path. The likely cause is you're including dom4j in your WAR/lib directory

James R. Perkins
  • 16,800
  • 44
  • 60
  • 1
    Yes thats what i think first- but my project doesnt include a dom4j dependency...and after google the problem, i found several posts where the editing of standalone.xml fixed it. – goblingift Sep 01 '16 at 08:20
  • 1
    I discovered that the adding of this dependency caused the issue: http://openimaj.org/openimaj-image/faces/dependencies.html There is the dom4j included...What can i do to fix the deployment error? – goblingift Sep 01 '16 at 08:21
  • 1
    If you're using maven you can add an exclude when you define the dependency. See https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html#Dependency_Exclusions – James R. Perkins Sep 01 '16 at 17:14