Running Ant

Command Line

If you've installed Ant as described in the Installing Ant section, running Ant from the command-line is simple: just type ant.

When no arguments are specified, Ant looks for a build.xml file in the current directory and, if found, uses that file as the buildfile and runs the "default" target. If you use the -find option, Ant will search for a buildfile first in the current directory, then in the parent directory, and so on, until either a buildfile is found or the root of the filesystem has been reached. To make Ant use a buildfile other than build.xml, use the command-line option -buildfile file, where file is the name of the buildfile you want to use.

You can also set properties that override properties specified in the buildfile (see the property task). This can be done with the -Dproperty=value option, where property is the name of the property, and value is the value for that property. This can also be used to pass in the value of environment variables. Just pass -DMYVAR=%MYVAR% (Windows) or -DMYVAR=$MYVAR (Unix) to Ant - you can then access these variables inside your buildfile as ${MYVAR}. You can also access environment variables using the property task.

Options that affect the amount of logging output by Ant are: -quiet, which instructs Ant to print less information on the console when running; -verbose, which causes Ant to print additional information to the console; and -debug, which causes Ant to print considerably more additional information.

It is also possible to specify one or more targets that should be executed. When omitted, the target that is specified in the default attribute of the project tag is used.

The -projecthelp option prints out a list of the buildfile's targets, along with the text in the description attribute of the target, if one was specified, followed by a list of those targets without one.

Command-line Options Summary

ant [options] [target [target2 [target3] ...]]
Options:
  -help                  print this message
  -projecthelp           print project help information
  -version               print the version information and exit
  -quiet                 be extra quiet
  -verbose               be extra verbose
  -debug                 print debugging information
  -emacs                 produce logging information without adornments
  -logfile <file>        use given file for log
  -logger <classname>    the class which is to perform logging
  -listener <classname>  add an instance of class as a project listener
  -buildfile <file>      use given buildfile
  -D<property>=<value>   use value for given property
  -propertyfile <name>   load all properties from file with -D
                         properties taking precedence
  -inputhandler <class>  the class which will handle input requests
  -find <file>           search for buildfile towards the root of the
                         filesystem and use it

For more information about -logger and -listener see the section Loggers & Listeners

For more information about -inputhandler see the section InputHandler

Examples

ant

runs Ant using the build.xml file in the current directory, on the default target.

ant -buildfile test.xml

runs Ant using the test.xml file in the current directory, on the default target.

ant -buildfile test.xml dist

runs Ant using the test.xml file in the current directory, on a target called dist.

ant -buildfile test.xml -Dbuild=build/classes dist

runs Ant using the test.xml file in the current directory, on a target called dist, setting the build property to the value build/classes.

Files

The Ant wrapper script for Unix will source (read and evaluate) the file ~/.antrc before it does anything - the Windows batch file invokes %HOME%\antrc_pre.bat at the start and %HOME%\antrc_post.bat at the end. You can use these files to set/unset environment variables that should only be visible during the execution of Ant. See the next section for example.

Environment Variables

The wrapper scripts use the following environment variables (if set):

Running Ant via Java

If you have installed Ant in the do-it-yourself way, Ant can be started with:

java -Dant.home=c:\ant org.apache.tools.ant.Main [options] [target]

These instructions actually do exactly the same as the ant command. The options and target are the same as when running Ant with the ant command. This example assumes you have set your classpath to include:



Copyright © 2000-2002 Apache Software Foundation. All rights Reserved.