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="..">

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

  <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"/>

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

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

  <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"/>
    <copy todir="${build.dir}/classes-ant">
      <fileset dir="${build.dir}/src">
        <include name="**/*.gif"/>
        <include name="**/*.jpg"/>
        <include name="**/*.png"/>
      <fileset dir="${build.dir}">
        <include name="reports/**/*.*"/>

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


Add new comment

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

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.