JavaFAQ Home » Java Installation, tunning, options...
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. A generic
file is given below that might be appropriate for student programs.
Obtaining and installing Ant
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 (
be set to where your JDK directory is). Installation instructions can be found
ant/docs/manual/index.html 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
To PATH add %ANT_HOME%in
Ant can be used from many IDEs, but I typically use it from a DOS/Command
- Set up
ant as above.
build.xml (see below) into your project directory.
- Open a DOS/Command window and move (
cd) to the directory
containing your source files.
ant to compile your source files. The
source="1.4" option is already specified so assertions are enabled at
- I use a text editor and flip back and forth between editing and the DOS
window to make changes, fix bugs, etc.
- Run the program with "
java -ea YourProg" ("-ea" enables
For simple development where the source and object files are in the same
directory and there's no explicit package (typical student project
organization), the following
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.
the root of the documentation.
|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".
Printer Friendly Page
Send to a Friend
Search here again if you need more info!