DataNucleus and NetBeans 7.0

Perhaps the most important step in developing applications with DataNucleus is the enhancement
of compiled classes. NetBeans provides a convenient way of
integrating this procedure into the build process without the need for any additional tool or plugin.
This is possible because NetBeans has native integration with Maven and Ant. Any DataNucleus project
based on Maven will open and run as is with Netbeans. No changes are needed in the project nor in
Netbeans. When using Ant Class enhancement thus becomes a simple matter of adding a new task to the
existing build.xml generated by NetBeans.

This tutorial shows how to integrate DataNucleus with NetBeans 7.0 to simplify the development of
JDO applications. Please contribute any updates to this guide that you have since the developers
of DataNucleus don't use Netbeans

Requirements

The following components are required to complete this tutorial successfully:

Working with Maven-based DataNucleus Project

NetBeans has native integration with Maven. If your project builds with Maven then it will also
build with NetBeans without any change. Unzip the sample project to
$home/DNSamples/datanucleus-samples-jdo-tutorial-3.0

The sample project comes with a pom.xml. When you try to open this project NetBeans will
automatically detect it as maven project.

Setting up NetBeans for DataNucleus ANT use

The first thing to do is to register the DataNucleus components in the Library Manager of
NetBeans 7 so that these become available to any project created with the IDE. This involves
creating a new library and adding the JAR files to it, as shown in the following screenshots

Open Library Manager

Add New Library with Name DN3 - Repeat the process for DN3Deps

Add all the libraries under $home/datanucleus-accessplatform-full-deps-3.0.0-release/lib
to DN3. Add all the libraries under $home/datanucleus-accessplatform-full-deps-3.0.0-release/deps
to DN3Deps

Once this is done, the NetBeans 7 will add the JAR files to the classpath whenever the
newly-created DN3 and DN3Deps library is selected for a project.

Setting up a new project

Delete pom.xml from the downloaded samples project. NetBeans treats any folder with
pom.xml as maven project. Copy the datanucleus.properties to src/java in the downloaded
samples project.

Now create a new project from existing sources.

Remember to Select Java Project with Existing Source

Click Next and Add Folder. The source folder should point to
datanucleus-samples-jdo-tutorial-3.0/src/java

Then click Next and Finish

Now we have the sucessfuly created the sample project using Ant

Add the Libraries created in first set to this project. Right-Click on Libraries in the Projects Tab

Add DN3 library to your project. Also add DN3Deps

We also need to add JDBC support to our project. Add this using add Add jars option.
Right-Click on Libraries in the Projects Tab and select Add jars

Add hsqldb

Enhancing the classes

The enhancement process needs to be defined and integrated into the build process. As
stated in the introduction, this requires a simple change to the nbbuild.xml file.

This target is the most convenient for enhancing classes because it occurs just after
all classes have been compiled and is called in any case, whether the project is being built,
tested or deployed. This ensures that classes are always enhanced.
Ensure that the Compile on Save option is turned off.Enable Annotation Processing should be turned ON

Building the project

The project can now be built, with the knowledge that the classes will be enhanced in
the process.

Output window will show some thing similar to this

BUILD SUCCESSFUL (total time: 2 seconds)
Run the main class
The output window will show as below
Product and Book have been persisted
Retrieving Extent for Products
>> Book : JRR Tolkien - Lord of the Rings by Tolkien
>> Product : Sony Discman [A standard discman from Sony]
Executing Query for Products with price below 150.00
>> Book : JRR Tolkien - Lord of the Rings by Tolkien
Deleting all products from persistence
Deleted 2 products
End of Tutorial
BUILD SUCCESSFUL (total time: 2 seconds)

Conclusion

This concludes our tutorial on how to integrate DataNucleus with NetBeans 7. As can be seen,
thanks to NetBeans project system based on Ant and Native Maven support, development of JDO
applications is largely simplified.
This tutorial was provided by a user of this software, Kiran Kumar.