Configuration

Once Ant is installed properly, it requires very little additional configuration. Provided the ant.bat batch file (or ant shell script) is installed in a directory that is included in your system path, you should be able to run Ant from any command prompt.

You do not technically have to use the provided ant or ant.bat script to run Ant. You can run Ant manually, as long as the following items are configured:[11]

  • The system CLASSPATH includes ant.jar and any JAXP-compliant XML parser.

  • For JDK 1.1, classes.zip must be added to the CLASSPATH. For Java 2, tools.jar must be added. This is necessary for tasks like javac.

  • Many tasks require that the ant.home Java system property be set to the Ant installation directory. This is accomplished by launching the JVM with the -D flag, as shown shortly.

  • JAR files for optional tasks must be added to the CLASSPATH.

Provided that these items are all set properly, you can use the following command to invoke Ant:[12]

java -Dant.home=pathToAnt org.apache.tools.ant.Main

Tip

Understanding how to set up and run Ant manually might be useful if you are making customizations to Ant and wish to run it using your IDE’s debugger.

XML Issues

Early versions of Ant (prior to Version 1.4) include Sun’s Java API for XML Parsing (JAXP) Version 1.0. Ant Versions 1.4 and later ship with JAXP 1.1, as described in the next paragraph. JAXP is an API allowing Java programs to use XML parsers from different vendors in a portable way. The JAXP JAR files, jaxp.jar ...

Get Ant: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.