Skip to main content

Source code file content

Revision: 596ec991c20ca0a6448cd2fc400d14ad9d4a5195

Adding simple build.xml
» Project Revision History

» Checkout URL

ant-super-simple-code / build.xml

Size: 3930 bytes, 1 line
Ant simple sample project.
 Kick start your java builds.
 Find out more at
Put this file in an empty directory and run the 'ant' command in that directory. The build file will create directories and make a very empty jar file in the same directory as the build.xml.

Create src/ and put this code in it.

public class HW
    public static void main(String [] args)
        System.out.println("Hello World");


in the build file below change  
<property name="main_class_name" value="changeme"/> 
<property name="main_class_name" value="HW"/>
Run the ant command again, and now you can run your main class with the command
java -jar antsimple.jar

It should print:
Hellow World
and exit.

Add a junit.jar (from into your ANT_HOME/lib directory and run 'ant test'
Create the file test/ and add this code.
import junit.framework.*;
public class HWTest extends TestCase {
    public void testTrue()


<project name="antsimple" default="dist" basedir=".">
        Ant Simple Sample File
  <!-- set global properties for this build -->
  <property name="" value="antsimple"/>
  <property name="main_class_name" value="changeme"/>
  <property name="jarname"  value="${}"/> 
  <!-- set directories -->
  <property name="src" location="src"/>
  <property name="test" location="test"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>
  <property name="lib"  location="lib"/>

  <path id="project.classpath">
    <pathelement location="${build}" />
    <pathelement location="${lib}" />

  <target name="init">
    <!-- Create the time stamp -->
    <!-- Create directories if needed -->
    <mkdir dir="${src}"/>
    <mkdir dir="${test}"/>
    <mkdir dir="${build}"/>
    <mkdir dir="${dist}"/>

  <target name="compile" depends="init" description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac debug="true" 
    <!-- Copy files from ${src} into ${build} -->
    <copy todir="${build}"> 
        <fileset dir="${src}">
          <exclude name="**/*.java"/>

  <target name="test" depends="compiletest" description="run the tests " >
    <junit printsummary="yes" fork="yes" haltonfailure="yes">
      <formatter type="plain"/>
      <batchtest fork="true">
        <fileset dir="${test}">
          <include name="**/*Test*.java"/>
      <classpath refid="${project.classpath}" />

  <target name="compiletest" depends="compile"
        description="compile the tests " >
        <javac debug="true" 
               classpathref="project.classpath" />

  <target name="dist" depends="compile" description="generate the distribution" >
    <!-- Create the distribution directory -->

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/${jarname}-${DSTAMP}.jar" basedir="${build}">
        <attribute name="Main-Class"
    <copy file="${dist}/${jarname}-${DSTAMP}.jar" tofile="./${jarname}.jar" overwrite="true"/>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} directory-->
    <delete dir="${build}"/>

Please Confirm