The ANT task WsJpaDB2GenTask provides an alternative to the wsdb2gen command.
The WsJpaDB2GenTask ANT task utility allows users to utilize the pureQuery feature in Java Persistence API (JPA) applications. Instead of executing the wsdb2gen from the command line, you can use the example code in your ANT build XML file to use the WsJpaDB2GenTask in your build process.
Both the PDQ runtime Java archive (JAR) files, pdq.jar and pdqmgmt.jar, must be specified using the ANT -lib option.
<!-- invoke this build using the ANT command ant jar -noclasspath -lib c:/was7/lib/j2ee.jar -lib c:/was7/plugins/com.ibm.ws.jpa.jar -lib c:/sqllib/java/db2jcc.jar -lib c:/sqllib/java/db2jcc_license_cu.jar -lib c:/sqllib/java/pdq.jar -lib c:/sqllib/java/pdqmgmt.jar -->When calling the ANT command, the JAR files for IBM Optim pureQuery Runtime, JPA and the JDBC driver must be on the library list.
<?xml version="1.0"?> <project name="sample" default="jar"> <taskdef name="enhancer" classname="org.apache.openjpa.ant.PCEnhancerTask" /> <taskdef name="wsdb2gen" classname="com.ibm.websphere.persistence.pdq.ant.WsJpaDB2GenTask" /> <target name="clean" description="remove intermediate files"> <delete dir="classes"/> <delete dir="enhanced" /> <delete> <fileset dir="." includes="META-INF/*.pdqxml" /> <fileset dir="." includes="sample.jar" /> </delete> </target> <target name="compile" description="compile the Java source code to class files"> <mkdir dir="classes"/> <javac srcdir="." destdir="classes"> <classpath> <pathelement location="c:/was7/lib/j2ee.jar"/> <pathelement location="c:/was7/plugins/com.ibm.ws.jpa.jar" /> </classpath> </javac> </target> <target name="enhance" depends="compile" > <mkdir dir="enhanced" /> <enhancer directory="./enhanced" > <config propertiesFile="META-INF/persistence.xml" /> <classpath> <pathelement location="." /> <pathelement location="classes" /> </classpath> </enhancer> </target> <target name="wsdb2gen" depends="enhance" > <wsdb2gen pu="MyAntTest" url="jdbc:db2://localhost:50000/demodb" user="user1" pw="secret" > <classpath> <pathelement location="."/> <pathelement location="enhanced" /> </classpath> </wsdb2gen> </target> <target name="jar" depends="wsdb2gen" description="create a Jar file for the application"> <jar destfile="sample.jar"> <fileset dir="classes" includes="**/*.class"/> <fileset dir="." includes="META-INF/*.xml" /> </jar> </target> </project>