Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Saturday, September 3, 2016

org.dom4j ClassCastException on WildFly Deployment

When forming a WAR file containing JPA entities for deployment in WildFly, I sometimes get get the following error.

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

Despite recommendations to the contrary, I add a jboss-deployment-structure.xml that excludes this module.  See this WildFly issue.  I did some A/B testing with exhaustive cleans and re-deploys and wasn't able to get this to dispel the ClassCastException.

I used two different fixes on different occasions.

1. Make sure the datasource is good.

2. Make sure that you're not packing your own Hibernate.

The newer versions of Gradle let you exclude Hibernate libs from your deployable using the compileOnly (not the compile) task.  This works exactly like the maven provided scope.


This is the dependencies section of the Gradle file I'm using to deploy a RESTful web services WAR file that includes EJBs and JPA.  There are some extra libs in there that I use on all my projects like Commons Codec.

dependencies {

    compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0.1'
    compileOnly group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.1.0.Final'
    compileOnly group: 'org.hibernate', name: 'hibernate-validator', version: '5.2.4.Final'
    compile group: 'com.google.guava', name: 'guava', version: '19.0'
    compile group: 'log4j', name: 'log4j', version: '1.2.17'
    compile group: 'org.jboss.ejb3', name: 'jboss-ejb3-ext-api', version: '2.2.0.Final'
    compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
    compile group: 'javax', name: 'javaee-api', version: '7.0'

    // The following dependencies will be the ear modules and
    // will be placed in the ear root
    // deploy project(':war')

    // The following dependencies will become ear libs and will
    // be placed in a dir configured via the libDirName property
    // earlib group: 'log4j', name: 'log4j'
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

No comments:

Post a Comment