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 (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.
This tutorial shows how to integrate JPOX with NetBeans (4.x) to simplify the development of
JDO applications.
JPOX is the predecessor to DataNucleus, and any change should be a simple change of "jpox" for
"datanucleus". Please contribute any updates to this guide that you have since the developers of
DataNucleus don't use Netbeans
The following components are required to complete this tutorial successfully:
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.
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.
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.
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}"
includes="**/*.jdo,**/*.properties,**/*.dtd,**/*.xml"/>
</copy>
<path id="module.enhancer.classpath">
<pathelement path="${javac.classpath}"/>
<pathelement location="${build.classes.dir}"/>
</path>
<taskdef name="jpoxenhancer"
classpathref="module.enhancer.classpath"
classname="org.jpox.enhancer.tools.EnhancerTask" />
<jpoxenhancer classpathref="module.enhancer.classpath"/>
</target>
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.
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 project system based on Ant, development of JDO applications is largely simplified.
This tutorial was provided by a user of this software, Eddy Young.