Previous Section
Table of Contents
Next Section


Running Ant

When the installation process is complete, you can run Ant to execute various tasks. You can run Ant by:

Using the Command Line

The command line is an instruction that you write to execute an application. To run Ant manually, you should know the command-line options to invoke Ant. The following command shows how to invoke Ant using command-line options:

ant [options] [target [target2 [target3...]]]

If you do not specify any option, Ant searches the build.xml file in the current directory and uses the build.xml file as a buildfile to execute the target in the default attribute of the <project> tag.

Table 1-8 lists the command-line options to run Ant:

Table 1-8: Command-Line Options

Option

Description

-help, -h

Prints help information that describes the Ant command and its options.

-projecthelp, -p

Prints the user-written help document present in the buildfile.

-version

Prints the version information of Ant.

-diagnostics

Prints the information that is helpful for analyzing problems and then reporting them.

-quiet, -q

Restrains the messages that the echo task in the buildfile does not initiate. As a result, this option instructs Ant to print less information on the console.

-verbose, -v

Prints complete information about all the operations occurring during a build. The option is exclusive to –debug.

-debug, -d

Prints debugging messages. The option is exclusive to –verbose.

-emacs, -e

Produces logging information.

-lib <path>

Specifies the path to locate jars and classes.

-logfile <file>

Forwards the logging output to the specified file.

-logger <classname>

Specifies the class that performs Ant logging.

-listener <classname>

Declares a listening class of Ant to add it as a project listener.

-buildfile <filename>, -file, -f

Specifies the buildfile on which Ant should function. The default value is build.xml.

-find <filename>

Searches the buildfile on which Ant should function. The –find option differs from the –buildfile option because unlike –buildfile, -find makes Ant search the specified file in the parent directory if the file is not present in the current directory.

-inputhandler <class>

Specifies the class that handles all the input requests.

Using Java

Using Java, you can initiate Ant using two methods:

  • The first method does not support the -lib option. As a result, you need to load all the options and all the classes from the CLASSPATH and include all the required jars in the CLASSPATH. The following code shows the first method to initiate Ant using Java:

    java -Dant.home=c:\ant org.apache.tools.ant.Main [options] [target]
    
  • The second method supports the -lib option and loads jars from the specified ANT_HOME. The following code shows the second method to initiate Ant using Java:

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

You must set all the environment variables, such as ANT_HOME, JAVA_HOME, and CLASSPATH, to run Ant. The CLASSPATH environment variable must include:

  • ant.jar: Executes the application using the main class.

  • ant.launcher.jar: Executes the application using launcher.

  • jars/classes for XML parser: Specifies the type of JAR file according to the type of XML parser that you use for execution. The various types of Java-based XML parsers are DOM, JAXP, SAXP, and SAX.

  • JDK's require jar/zip files: Contains various tools, such as javac, java, javadoc, jar, javah, and javap, which help build and compile the application.



Previous Section
Table of Contents
Next Section