Ant is the most commonly used "make" facility for Java programs. After editing source programs, it's necessary to recompile. Ant checks the last change date on .class and .java files and recompiles source files where the .class date is older than the corresponding .java file.
Ant also supports many additional tasks, for example, running
to produce documentation, running tests, building jar files, ...
The action of ant is determined by a
build.xml file is given below that might be
appropriate for student programs.
Ant is free from the Apache Software Foundation (ant.apache.org).
To install it on Windows unzip it into a directory (eg,
and set the following three environment variables (
should be set to where your JDK directory is).
Installation instructions can be found at
in the ant directory and online.
The environment variables ANT_HOME, JAVA_HOME, and PATH must be set (eg, Settings - Control Panel - System - Advanced - Environment Variables - System Variables).
ANT_HOME=c:\ant JAVA_HOME=c:\jdk1.4.2_04 To PATH add %ANT_HOME%\bin
Ant can be used from many IDEs, but I typically use it from a DOS/Command window.
build.xml(see below) into your project directory.
cd) to the directory containing your source files.
antto compile your source files. The
source="1.4"option is already specified so assertions are enabled at compile time.
java -ea YourProg" ("-ea" enables run-time assertions).
For simple development where the source and object files are in the same
directory and there's no explicit package (typical student project organization),
build.xml file can be used.
This works correctly if all top-level classes are in separate files.
The following ant commands can be used.
|Compiles source files (defaults to build).|
|Compiles source files. Same as above.|
|Creates javadoc documentation in a docs directory.
It creates the docs directory if necessary.
|Deletes all .class files and the docs directory. This must be done whenever a class has been renamed or removed, before final builds, and just every so often to help detect "code rot".|
<?xml version="1.0"?> <project name="generic" default="build" basedir="."> <!-- ================================================= build --> <target name="build" description="Compile source files"> <javac srcdir="." source="1.4" debug="true"/> </target> <!-- ================================================== docs --> <target name="docs" depends="build" description="Generate javadoc documentation."> <javadoc destdir="docs" private="true" source="1.4"> <fileset dir="." includes="*.java"/> </javadoc> </target> <!-- ================================================== clean --> <target name="clean" description="Delete class files and docs dir."> <delete> <fileset dir="." includes="*.class"/> </delete> <delete dir="docs" /> </target> </project>