A sample ant build script for a standalone Java application

Ant Java build scripts: Can you share an example of an Ant build script for a standalone Java application?

This is a sample Ant build script for a Java application I wrote. It is a GUI/Swing application named "AlwaysOnTop". I include it here because I'm a big believer in learning by example, and maybe this Ant script can help you create an Ant script for your own applications.

  <project name="alwaysontop" default="make_jar" basedir="..">

  <!-- IMPORTANT VARIABLE HERE -->
  <property name="build.dir" value="C:/Projects_LocalCVS/DevDaily/AlwaysOnTopTest"/>
  <path id="class.path">
    <fileset dir="lib">
      <include name="**/*.jar"/>
      <include name="**/*.zip"/>
    </fileset>
  </path>

  <target name="init">
     <property name="project_name"   value="alwaysontop"/>
     <property name="jar"            value="${build.dir}/jar/${project_name}.jar"/>
     <property name="mainclass"      value="com.devdaily.alwaysontoptest.Main"/>
     <property name="sampleDataDir"  value="${build.dir}/data"/>
     <property name="nameOfDataDir"  value="data"/>
    <tstamp/>
  </target>

  <target name="create_classes_dir" depends="init">
    <mkdir dir="${build.dir}/classes-ant"/>
  </target>

  <!-- CLEAN TARGET -->
  <target name="clean">
    <delete dir="${build.dir}/classes-ant"/>
  </target>

  <!-- COMPILE TARGET -->
  <target name="compile" depends="clean,create_classes_dir">
    <javac destdir="${build.dir}/classes-ant" source="1.4" >
      <src path="src"/>
      <exclude name="**/_*.java"/>
      <classpath refid="class.path"/>
    </javac>
    <copy todir="${build.dir}/classes-ant">
      <fileset dir="${build.dir}/src">
        <include name="**/*.gif"/>
        <include name="**/*.jpg"/>
        <include name="**/*.png"/>
      </fileset>
      <fileset dir="${build.dir}">
        <include name="reports/**/*.*"/>
      </fileset>
    </copy>
  </target>


  <!-- MAKE JAR TARGET -->
  <target name="make_jar" depends="compile">
    <jar basedir="${build.dir}/classes-ant" 
         jarfile="${build.dir}/jar/${project_name}.jar" 
         manifest="${build.dir}/build/${project_name}.manifest"
         includes="**/*.*"/>
    <copy todir="${build.dir}/jar">
      <fileset dir="${build.dir}/lib">
        <include name="**/*.jar"/>
        <include name="**/*.zip"/>
      </fileset>
    </copy>
  </target>

</project>

Post new comment

The content of this field is kept private and will not be shown publicly.