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.
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.
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. 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>3.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>
</plugins>
</build>
</project>So whenever compile takes place it then does an enhance using the DataNucleus Maven2 plugin. See also the Enhancer docs SchemaTool is achieved similarly, via
mvn datanucleus:schema-create
See also the DataNucleus SchemaTool docs
At compilation you only need the JDO (and also JPA if using JPA) jar
<project>
...
<dependencies>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
...
</project>
If using JDO then just the first dependency is required. You do not need DataNucleus jars here unless you are explicitly referencing any DataNucleus classes in your application.
At runtime you obviously need to include the relevant DataNucleus jars for its operation
<project>
...
<dependencies>
...
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jpa</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies>
...
</project>
As a minimum you will need the jdo-api jar and if using JPA you then will need persistence-api also (see "Building" above). To run DataNucleus you need the datanucleus-core jar as well as the jar for the datastore being utilised e.g datanucleus-rdbms , as well as the API jar datanucleus-api-jdo / datanucleus-api-jpa Note that DataNucleus uses Maven2 version ranges in its poms. This means that it allows ranges of versions of the different plugins to be used together. Read up on the version range syntax of Maven2 to understand better. This is particularly important when using the DataNucleus Maven2 plugin, and if having problems with auto-updating then make sure you have the latest version for that release cycle |