3.15.1.4. Mapping Tool Ant Task

The mapping tool task allows you to directly invoke the mapping tool from within the Ant build process. It is useful for making sure that the database schema and object-relational mapping data is always synchronized with your persistent class definitions, without needing to remember to invoke the mapping tool manually. The task’s parameters correspond exactly to the long versions of the command-line arguments to the org.apache.openjpa.jdbc.meta.MappingTool.

The mapping tool 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 file or openjpa.MetaDataFactory property.

Following is an example of a build.xml target that invokes the mapping tool:

Example 173. Invoking the Mapping Tool from Ant
<target name="refresh">
  <!-- define the mappingtool task; this can be done at the top of -->
  <!-- the build.xml file, so it will be available for all targets -->
  <taskdef name="mappingtool" classname="org.apache.openjpa.jdbc.ant.MappingToolTask"/>

  <!-- add the schema components for all .jdo files below the      -->
  <!-- current directory                                           -->
  <mappingtool action="buildSchema">
    <fileset dir=".">
      <include name="**/*.jdo" />
    </fileset>
  </mappingtool>
</target>