How to add Datanucleus Module in Wildfly

How do you add a Module in Wildfly J2EE server?

The Wildfly ( Java EE server has concept of “Module” to add external libraries. This involve creating a directory to deploy the jars and a xml file that describes the library.

Following is the example of adding Datanucleus JPA jars in the Wildfly version 10.

  1. Create a directory to store the DataNucleus libraries, in
  2. Add the following jars from the lib directory:
  3. Add a “module.xml” file in the $JBOSS_HOME/modules/org/datanucleus/main directory like this
    <module xmlns="urn:jboss:module:1.1" name="org.datanucleus">
    <module name="javax.api"/>
    <module name="javax.persistence.api"/>
    <module name="javax.transaction.api"/>
    <module name="javax.validation.api"/>
    <resource-root path="datanucleus-api-jpa-xxxxx.jar"/>
    <resource-root path="datanucleus-core-xxxxx.jar"/>
    <resource-root path="datanucleus-rdbms-xxx.jar"/>
    <resource-root path="datanucleus-jpa-query-xxxx.jar"/>
  4. Example of Datanucleus persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="" version="1.0">
    <persistence-unit name="[Persistence Unit Name]" transaction-type="JTA">
        <!-- MySQL DS -->

        <class>[Entities must be listed here]</class>

            <!-- Magic JBoss property for specifying the persistence provider -->
            <property name="" value="org.datanucleus"/>

            <!-- following is probably not useful... but it ensures we bind to the JTA transaction manager...-->
            <property name="datanucleus.jtaLocator" value="custom_jndi"/>
            <property name="datanucleus.jtaJndiLocation" value="java:/TransactionManager"/>

            <property name="datanucleus.autoCreateSchema" value="true"/>
            <property name="datanucleus.metadata.validate" value="false"/>
            <property name="datanucleus.validateTables" value="false"/>
            <property name="datanucleus.validateConstraints" value="false"/>

Second way of adding your application libraries?

Besides adding module in Wildfly, you may add those libraries in your application war file. If you are using Maven, add dependency in your parent pom. When war is built, those libraries will be included in the WEB-INF/lib.