Skip to content
mkarneim edited this page Oct 5, 2014 · 1 revision

Here is an ANT build script that runs the PojoBuilder annotation processor within the javac task:

<?xml version="1.0"?>
<project name="pojobuilder.samples" default="main" basedir=".">
  <property file="build.local.properties" />
  <property file="${build.system.properties.file}" />


  <!-- Folders and files -->
  <property name="src.dir" location="${basedir}/src" />
  <property name="lib.dir" location="${basedir}/lib" />
  <property name="src.main.java.dir" location="${src.dir}/main/java" />
  <property name="src.gen.java.dir" location="${src.dir}/generated/java" />

  <property name="build.dir" location="${basedir}/build" />
  <property name="build.classes.dir" location="${build.dir}/classes" />

  <!-- Libraries -->
  <!-- Add the required libraries into this directory. -->
  <fileset id="libs.fileset" dir="${lib.dir}">
    <include name="*.jar" />
  </fileset>

  <path id="class.path">
    <fileset refid="libs.fileset" />
  </path>

  <!-- Targets  -->
  <target name="init">
    <tstamp>
      <format property="build.time" pattern="MMM/dd/yyyy hh:mm aa z" />
    </tstamp>
  </target>

  <target name="check-library-directory-is-not-empty">
    <condition property="libs.fileset.empty">
      <length length="0">
        <fileset refid="libs.fileset" />
      </length>
    </condition>
    <fail if="libs.fileset.empty">
    Missing library.
    The library directory ${lib.dir} is empty.
    Please add pojobuilder-*-jar-with-dependencies.jar.
    You can download it from http://search.maven.org/#search|ga|1|a%3A%22pojobuilder%22.
    </fail>
  </target>

  <target name="clean" depends="init" description="Clean up all generated files">
    <delete dir="${build.dir}" />
    <delete dir="${src.gen.java.dir}" />
  </target>

  <target name="compile" depends="init, check-library-directory-is-not-empty" description="Compile java sources and run annotation processor">
    <mkdir dir="${src.gen.java.dir}" />
    <mkdir dir="${build.classes.dir}" />
    <javac classpathref="class.path" destdir="${build.classes.dir}">
      <src path="${src.main.java.dir}" />
      <!-- This tells the compiler where to place the generated source files -->
      <compilerarg line="-s ${src.gen.java.dir}" />
    </javac>
  </target>

  <target name="run" depends="init, compile" description="Runs the main class">
    <java classname="Main">
      <classpath>
        <pathelement location="${build.classes.dir}" />
      </classpath>
    </java>
  </target>

  <target name="main" depends="init, clean, compile, run" description="build all artifacts">
  </target>
</project>