title: Exception in wildfly 10: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
body: <p>I have a maven project that works fine in wildfly-8.2, but when I deployed it in wildfly-10, I am getting error -</p>
  
  <pre><code>java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:179)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:121)
      at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:193)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
      at org.jboss.threads.JBossThread.run(JBossThread.java:320)
  Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
      at org.dom4j.DocumentFactory.getInstance(DocumentFactory.java:97)
      at org.hibernate.internal.util.xml.XMLHelper$1.doWork(XMLHelper.java:33)
      at org.hibernate.internal.util.xml.XMLHelper$1.doWork(XMLHelper.java:27)
      at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.workWithClassLoader(ClassLoaderServiceImpl.java:342)
      at org.hibernate.internal.util.xml.XMLHelper.&lt;init&gt;(XMLHelper.java:26)
      at org.hibernate.envers.boot.internal.EnversServiceImpl.initialize(EnversServiceImpl.java:115)
      at org.hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl.produceAdditionalMappings(AdditionalJaxbMappingProducerImpl.java:99)
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:288)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
      at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:161)
      ... 7 more
  </code></pre>
  
  <p>I searched on the internet about this error and got many posts on this error. I tried many but no luck. I checked wildfly-10 and my application and both have dom4j-1.6.1.jar. Firstly, I removed dom4j-1.6.1.jar from my application and I got a compilation error. Then, I removed dom4j-1.6.1 from JBOSS module and JBOSS started to throw me exception at the start up. </p>
  
  <p>My pom.xml is -</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;com.rolta.oneview.platform&lt;/groupId&gt;
          &lt;artifactId&gt;OV-PLF&lt;/artifactId&gt;
          &lt;version&gt;1.0&lt;/version&gt;
      &lt;/parent&gt;
      &lt;artifactId&gt;platform-war&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;name&gt;platform-war&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
              &lt;version&gt;1.0.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/org.springframework.webflow/spring-webflow --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.webflow&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webflow&lt;/artifactId&gt;
              &lt;version&gt;2.4.2.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;commons-beanutils&lt;/groupId&gt;
              &lt;artifactId&gt;commons-beanutils&lt;/artifactId&gt;
              &lt;version&gt;1.9.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;4.3.9.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.common&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-commons-annotations&lt;/artifactId&gt;
              &lt;version&gt;4.0.5.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.webflow&lt;/groupId&gt;
              &lt;artifactId&gt;spring-binding&lt;/artifactId&gt;
              &lt;version&gt;2.4.0.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
              &lt;version&gt;4.3.0.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;1.2.17&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
          &lt;groupId&gt;org.jasypt&lt;/groupId&gt;
          &lt;artifactId&gt;jasypt&lt;/artifactId&gt;
          &lt;version&gt;1.9.2&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.rolta.oneview.platform&lt;/groupId&gt;
              &lt;artifactId&gt;license-service&lt;/artifactId&gt;
              &lt;version&gt;1.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
              &lt;artifactId&gt;resteasy-jaxrs&lt;/artifactId&gt;
              &lt;version&gt;2.2.1.GA&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.spec&lt;/groupId&gt;
              &lt;artifactId&gt;jboss-javaee-all-7.0&lt;/artifactId&gt;
              &lt;version&gt;1.0.3.Final&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/org.quartz-scheduler/quartz --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.quartz-scheduler&lt;/groupId&gt;
              &lt;artifactId&gt;quartz&lt;/artifactId&gt;
              &lt;version&gt;2.2.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
              &lt;artifactId&gt;gson&lt;/artifactId&gt;
              &lt;version&gt;2.7&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;4.3.0.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.rolta.oneview.products.processMgr&lt;/groupId&gt;
              &lt;artifactId&gt;agent.api&lt;/artifactId&gt;
              &lt;version&gt;1.0.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-client --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
              &lt;artifactId&gt;resteasy-client&lt;/artifactId&gt;
              &lt;version&gt;3.0.8.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt; &lt;!-- RESTeasy --&gt;
              &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
              &lt;artifactId&gt;jaxrs-api&lt;/artifactId&gt;
              &lt;version&gt;3.0.12.Final&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.rolta.oneview.platform&lt;/groupId&gt;
              &lt;artifactId&gt;msg-services&lt;/artifactId&gt;
              &lt;version&gt;1.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.rolta.iperspective.sso&lt;/groupId&gt;
              &lt;artifactId&gt;iPerspectiveSSO&lt;/artifactId&gt;
              &lt;version&gt;5.8&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.ws02&lt;/groupId&gt;
              &lt;artifactId&gt;wso2Agent&lt;/artifactId&gt;
              &lt;version&gt;1.2&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.opensaml&lt;/groupId&gt;
              &lt;artifactId&gt;opensaml&lt;/artifactId&gt;
              &lt;version&gt;2.4.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.rolta.aladdin&lt;/groupId&gt;
              &lt;artifactId&gt;safenet-sentinel-hasp-api&lt;/artifactId&gt;
              &lt;version&gt;1.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;xerces&lt;/groupId&gt;
              &lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
              &lt;version&gt;1.4.01&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;joda-time&lt;/groupId&gt;
              &lt;artifactId&gt;joda-time&lt;/artifactId&gt;
              &lt;version&gt;2.2&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.opensaml&lt;/groupId&gt;
              &lt;artifactId&gt;xmltooling&lt;/artifactId&gt;
              &lt;version&gt;1.3.2&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.apache.santuario/xmlsec --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.santuario&lt;/groupId&gt;
              &lt;artifactId&gt;xmlsec&lt;/artifactId&gt;
              &lt;version&gt;1.4.4&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.apache.velocity/velocity --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.velocity&lt;/groupId&gt;
              &lt;artifactId&gt;velocity&lt;/artifactId&gt;
              &lt;version&gt;1.5&lt;/version&gt;
              &lt;type&gt;pom&lt;/type&gt;
          &lt;/dependency&gt;
  
  
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;platform&lt;/finalName&gt;
  
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;webXml&gt;src\main\webapp\WEB-INF\web.xml&lt;/webXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>My Jboss-deployment-structure.xml is </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jboss-deployment-structure&gt;
      &lt;deployment&gt;
  
          &lt;exclusions&gt;
                  &lt;module name="org.dom4j" /&gt;
          &lt;/exclusions&gt;
          &lt;dependencies&gt;
              &lt;module name="com.rolta.platform" /&gt;
              &lt;module name="com.rolta.wso2" /&gt;
          &lt;/dependencies&gt;
      &lt;/deployment&gt;
  
  &lt;/jboss-deployment-structure&gt;
  </code></pre>
  
  <p>Please let me know, What changes should i do to come out of this problem. Thanks</p>