DataNucleus and NetBeans 4.0

Perhaps the most important step in developing applications with JPOX is the enhancement of compiled classes. NetBeans 4.x 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 4.x stores project information in .properties files and relies on Ant for the build process. Class enhancement thus becomes a simple matter of adding a new task to the existing build.xml generated by NetBeans 4.x.

This tutorial shows how to integrate JPOX with NetBeans 4.x to simplify the development of JDO applications.


The following components are required to complete this tutorial successfully:

Setting up NetBeans 4.x for JPOX use

The first thing to do is to register the JPOX components in the Library Manager of NetBeans 4.x 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.

Once this is done, the NetBeans 4.x will add the JAR files to the classpath whenever the newly-created JPOX library is selected for a project.

Setting up a new project

Now create a new project and add the JPOX library to it. This is done by viewing the properties for the project (right-click on the project and select Properties... ). Click on Add Library... and select the JPOX library that we created in the previous section.

Note that I store the properties for the PersistenceManagerFactory and for Log4j in .properties files within the source root folder. This varies according to personal preferences, but I have found this to be very efficient.

Write code and the metadata

The next step is to write the code for the classes and the meta-data. This is a straightforward exercise left to the reader. One note of advice, however. Because NetBeans 4.x does not recognise the package.jdo file, it does not auto-complete XML code as it is being entered. The reader may wish to edit the file as package.xml and instruct Ant, through an entry in the build.xml file to rename that file to package.jdo just before the enhancement is performed. This tutorial does not show how to do this.

Enhancing the classes

Once the code and the metadata has been written, 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 build.xml file.

Click on the Files tab, expand the project tree, then open build.xml .

Override the -post-compile task/target with the following Ant instructions.

    <target name="-post-compile">
        <echo message="Enhancing the MODULE files"/>

        <copy todir="${build.classes.dir}">
            <fileset dir="${src.dir}"

        <path id="module.enhancer.classpath">
            <pathelement path="${javac.classpath}"/>
            <pathelement location="${build.classes.dir}"/>

        <taskdef name="jpoxenhancer"
             classname="" />

        <jpoxenhancer classpathref="module.enhancer.classpath"/>        

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.

Building the project

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


This concludes our tutorial on how to integrate JPOX with NetBeans 4.x. As can be seen, thanks to NetBeans 4.x project system based on Ant, development of JDO applications is largely simplified. This tutorial was provided by a JPOX user Eddy Young.