Netbeans: Compile schemas into JAXB classes with XJC task

To add a XJC task to a Netbeans build.xml you need to add a -pre-compile target to your build.xml. If it’s a netbeans module build.xml then you need to make compile depend on -pre-compile and projectized-common.compile (see example below). For regular Java Applications just define the -pre-compile target as the standard build.xml will call -pre-compile before compile. Then it’s just a matter of defining the <taskdef> with the proper classpath to the jaxb’s jars. ...

October 1, 2009

OpenJPA Enhancer Ant task in a Netbeans project

In the build.xml of the project (likely this will be a Java Class Library project), override -post-compile or -pre-jar and invoke <openjpac/>. You will need to add the build/classes and the openjpa jars to <taskdef/> and <openjpac/>. The <openjpac/> will enhance all classes mentioned in persistence.xml (which has to be in the classpath) <?xml version="1.0" encoding="UTF-8"?> <project name="JpaEntitiesLibrary" default="default" basedir="."> <description>Builds, tests, and runs the project JpaEntitiesLibrary.</description> <import file="nbproject/build-impl.xml"/> <target name="-post-compile"> <echo message="begin openJPAC"/> <path id="openjpa.path.id"> <pathelement location="${build.classes.dir}"/> <!-- Adding the OpenJPA jars into the classpath --> <fileset dir="C:\Users\ecerulm\Downloads\apache-openjpa-1.2.1-binary\apache-openjpa-1.2.1\lib" includes="*.jar"/> <!-- or if you create a OpenJPA Library you can use that instead --> <!--<pathelement path="${libs.OpenJPA.classpath}"/>--> </path> <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask"> <classpath refid="openjpa.path.id"/> </taskdef> <openjpac> <classpath refid="openjpa.path.id"/> </openjpac> <echo message="end openJPAC"/> </target> </project> You can refer to the OpenJPA jars by either a <fileset> with the file path to the OpenJPA directory or by refererring to a Netbeans Library instead. You can create a OpenJPA Library via Tools ⇒ Libraries ⇒ New Library and add all the jars to the Library. If you name the library “OpenJPA” then you can refer to its classpath with <pathelement path="${libs.OpenJPA.classpath}"/>. See the commented code in the build.xml above. ...

September 16, 2009