DataNucleus and Maven2

Apache Maven is a project management and build tool that is quite common in organisations. It continues on from where Maven1 left off though not providing backwards compatibility with Maven1.

Repository

The main thing that you need to bear in mind is that DataNucleus jars are present in DataNucleus own Maven repository so all you need to do is point your Maven2 project at this repository. You do this by including the following in your pom.xml

<project>
    ...

    <repositories>
        <repository>
            <id>DataNucleus_Repos2</id>
            <name>DataNucleus Repository</name>
            <url>http://www.datanucleus.org/downloads/maven2</url>
        </repository>
        <repository> <!-- Required for transaction-api transitive dep -->
            <id>Java_Net_LEGACY</id>
            <name>Java.Net legacy</name>
            <url>http://download.java.net/maven/1/</url>
            <layout>legacy</layout>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>DataNucleus_2</id>
            <url>http://www.datanucleus.org/downloads/maven2/</url>
        </pluginRepository>
    </pluginRepositories>
</project>

So this make the DataNucleus Maven2 repository available, and also makes the DataNucleus Maven2 plugin available.





Maven2 Plugin

Now that you have the DataNucleus jars available to you, via the repositories, you want to perform DataNucleus operations. The primary operations are enhancement and SchemaTool (for RDBMS). To run the enhancer you do

mvn datanucleus:enhance
                

If you want this to be done automatically after compiling then you should add the following into your pom.xml

<project>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>maven-datanucleus-plugin</artifactId>
                <version>2.0.0-release</version>
                <configuration>
                    <log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
                    <verbose>true</verbose>
                    <props>${basedir}/datanucleus.properties</props>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugin>
    </build>
</project>

So whenever compile takes place it then does an enhance using the DataNucleus Maven2 plugin. See also the Enhancer docs

RDBMS SchemaTool is achieved similarly, via

mvn datanucleus:schema-create
                

See also the RDBMS SchemaTool docs