org.dom4j.DocumentFactory ClassCastException on Hudson

Recently we initialized a new CentOS server with a new Hudson and Wildfly 10 instance. During the process of deploying our Java project to a Wildfly instance we were faced with an annoying Exception:
java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

We fixed our problem with the instructions in the Wildfly ticket system. You need to create a file jboss-deployment-structure.xml in the META-INF folder of your wildfly instance. We placed the file in ../wildfly/modules/system/layers/base/org/jboss/as/product/wildfly-full/dir/META-INF with this content:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.dom4j"/>
</dependencies>
</deployment>
</jboss-deployment-structure>

So the Wildfly does use the dom4j library provided by Hudson and there is no ClassCastException.