JPOX
JPOX
 JPOX Version 1.0
Configuration | Tutorials | Worked Examples | Developer
Obtaining JPOX
JPOX Preparation
JPOX Runtime
Byte-Code Enhancer

JDO requires that all Persistence-Capable classes are byte-code enhanced in order to be utilisable by a JDO implementation in a persistence framework. Java Persistent Objects JDO (JPOX) provides its own byte-code enhancer (this can be found in the jpox-enhancer.jar). This section describes how to use this enhancer with JPOX. You can still use the SUN Reference Implementation enhancer if you wish, but the JPOX Enhancer provides much more elaborate error checking on classes and JDO Meta-Data files hence minimizing errors before application startup.

How to use the JPOX Enhancer depends on what environment you are using. Below are some typical examples. See also the EclipseJDO tutorial which provides details for that environment.

Manually

JPOX provides a JAR containing the Enhancer (jpox-enhancer.jar). If you are building your application manually and want to enhance your classes you follow the instructions in this section. You invoke the enhancer as follows

java -cp classpath  org.jpox.enhancer.JPOXEnhancer [options] [jdo-files]
    where options can be
        -d target-dir-name : Write the enhanced classes to the specified directory
        -checkonly : Just check the classes for enhancement status
        -verify : Verify the classes
        -v : verbose output

    where classpath contains the following
        jpox-enhancer.jar
        bcel.jar
        jdo.jar
        log4j.jar
        your classes

To give an example of how you would invoke this

java -cp classes:jpox-enhancer.jar:jdo.jar:log4j.jar:bcel.jar
     org.jpox.enhancer.JPOXEnhancer 
     **/*.jdo

[should all be on same line. Shown like this for clarity].

So you pass in your JDO MetaData files as the final argument in the list, and include the respective JAR's in the classpath (-cp) argument field, with your class files and JDO MetaData files being under "classes".

You can also use the JPOX Enhancer to check whether classes are enhanced. To invoke the enhancer in this mode you specify the checkonly flag

java -cp classes:jpox-enhancer.jar:jdo.jar:log4j.jar:bcel.jar
     org.jpox.enhancer.JPOXEnhancer 
     -checkonly
     **/*.jdo

This will return a list of the classes, stating whether each class is enhanced for persistence under JDO or not. The classes need to be in the CLASSPATH.

Maven

Maven operates from a series of plugins. There is a JPOX plugin for Maven that allows enhancement of classes. Go to the Download section of the website and download this. Once you have the Maven plugin, you then need to set the properties for the plugin in your project.properties file. This will typically not require any addition to your project.properties. If you do need to change this file, the following parameters are the likely ones to change

maven.jpox.jdo.fileset.dir=${maven.build.dest}  # Location of the JDO files
maven.jpox.jdo.fileset.include=**/*.jdo         # fileset to include
#maven.jpox.jdo.fileset.exclude=something.jdo   # fileset to exclude, if any
maven.jpox.classes.dir=${maven.build.dest}      # Location of classes to enhance
maven.jpox.log4j.configuration=                 # Log definition to use
maven.jpox.verbose=true                         # Turn on more output ?
                

You then run the Maven JPOX plugin, as follows

maven jpox:enhance

This will enhance all classes found that correspond to the classes defined in the JDO files in your source tree. If you want to check the current status of enhancement you can also type

maven jpox:enhance-check
Ant

Ant provides a powerful framework for performing tasks. JPOX provides an Ant task to enhance classes. JPOX provides a JAR containing the Enhancer (jpox-enhancer.jar). You need to make sure that the jpox-enhancer.jar, bcel.jar, log4j.jar and jdo.jar are in your classpath. In the JPOX Enhancer Ant task, the following parameters are available

ParameterDescriptionvalues
dirMandatory. Directory containing the JDO files to use for enhancing.
destinationOptional. Defining a directory where enhanced classes will be written. If omitted, the original classes are updated.
checkonlyWhether to just check the classes for enhancement status. Will respond for each class with "ENHANCED" or "NOT ENHANCED". This will disable the enhancement process and just perform these checks.true, false
verifyVerify the classes enhancement state. Performs more detailed checking on the enhancement consistency. This will disable the enhancement process and just perform these checks.true, false
verboseWhether to have verbose output.true, false

So you could define something like the following, setting up the parameters enhancer.classpath, jdo.file.dir, and log4j.config.file to suit your situation (the jdo.file.dir is a directory containing the JDO files defining the classes to be enhanced). The classes specified by the JDO Meta-Data files must be in the CLASSPATH.

<target name="enhance" description="JPOX enhancement">
    <taskdef name="jpoxenhancer" classname="org.jpox.enhancer.tools.EnhancerTask" />

    <jpoxenhancer classpathref="${enhancer.classpath}"
        dir="${jdo.file.dir}"
        failonerror="true"
        fork="true"
        verbose="false">
        <jvmarg line="-Dlog4j.configuration=${log4j.config.file}"/>
    </jpoxenhancer>
</target>