Ant

Intended for Windows users taking Java EIM related courses. Also refer to the original Ant installation instruction.

Description:
Ant and Maven are two alternative "build tools". Ant allows to write low level build scripts, where each action (copy, compile, zip, etc.) are written explicitly.
Download at:
http://ant.apache.org
Preconditions:
JDK 1.6 should be installed
  • Open Total Commander navigate to the file apache ant 1.6.5-bin.zip
  • Double-click the ZIP file; it will open and display the zipped directory apache-ant-1.7.0
  • Select the directory apache-ant-1.7.0 and press button F5 to copy (i.e. unzip) that directory under c:\tools.
  • Create a new Environment (System) variable ANT_HOME with the value c:\tools\apache-ant-1.7.0 (see Setting Environment Variables for info how to set environment variables).
  • Add a new directory to the Path entvironment variable, namely the %ANT_HOME%\bin directory.

Check the installation:

  • Open a DOS window window somewhere, type "ant -version" and check the response
c:\temp>ant -version
Note:
If you are new to Apache Ant, you may want to test the Ant installation by building some simple Ant project. For example, create a subdirectory c:\temp\src and copy some simple Java program e.g. a sample "Hello world" application Hello.java to this directory
build.xml
<project name="testproject" default="usage" basedir=".">

    <target name="usage" description="Message on how to use Ant buildfiles">
        <echo>Please use the 'build -projecthelp' to see a list of available build targets.</echo>
    </target>

    <target name="clean" description="Removes build artifacts">
        <delete dir="build" failonerror = "false"/>
    </target>

    <target name="init" depends="clean" description="Creates the directory structure for a simple Java project">
        <mkdir dir="build"/>
    </target>

    <target name="compile" depends="init"
            description="Compiles the sources">
        <echo level="info">Compiling files</echo>
        <javac srcdir="src"
            destdir="build"
            debug="true" 
            source="1.5"
            target="1.5"/>
    </target>

    <target name="run">
        <java classname="Hello" 
            fork="true"
            classpath="build">
        </java>
    </target>
</project>

Run the following commands in a DOS window:

c:\temp>ant
...
c:\temp>ant -projecthelp
...
c:\temp>ant compile
...
c:\temp>ant run
...

These should display

  1. a usage message,
  2. a list of all commands availabe in the Ant script,
  3. a message of successful compilation of the file c:\temp\src\Hello.java,
  4. the message printed out by the Java program.