3.15.1.2. Enhancer Ant Task

The enhancer task allows you to invoke the OpenJPA enhancer directly from within the Ant build process. The task’s parameters correspond exactly to the long versions of the command-line arguments to the org.apache.openjpa.enhance.PCEnhancer.

The enhancer task accepts a nested fileset tag to specify the files that should be processed. You can specify .java or .class files. If you do not specify any files, the task will run on the classes listed in your persistence.xml or openjpa.MetaDataFactory property. You must, however, supply the classpath you wish the enhancer to run with. This classpath must include, at minimum, the openjpa jar(s), persistence.xml and the target classes.

Following is an example of using the enhancer task in a build.xml file:

Example 171. Invoking the Enhancer from Ant
<target name="enhance">
    <!-- Define the classpath to include the necessary files. -->
    <!-- ex. openjpa jars, persistence.xml, orm.xml, and target classes  -->
    <path id="jpa.enhancement.classpath">
        <!-- Assuming persistence.xml/orm.xml are in resources/META-INF -->
        <pathelement location="resources/" />

        <!-- Location of the .class files -->
        <pathelement location="bin/" />

        <!-- Add the openjpa jars -->
        <fileset dir=".">
            <include name="**/lib/*.jar" />
        </fileset>
    </path>


    <!-- define the openjpac task; this can be done at the top of the -->
    <!-- build.xml file, so it will be available for all targets -->
    <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask" classpathref="jpa.enhancement.classpath" />

    <!-- invoke enhancer on all .class files below the model directory -->
    <openjpac>
        <classpath refid="jpa.enhancement.classpath" />
        <fileset dir=".">
            <include name="**/model/*.class" />
        </fileset>
    </openjpac>
    <echo message="Enhancement complete" />
</target>