Ant Build Files - Apache Ant

What is Ant Build Files?

Usually, Ant's build record, called build.xml must reside in the base listing of the project. however there is no limit at the record name or its place. you are loose to use different record names or save the build file in a few different region.

For this exercise, create a file known as build.xml anywhere on your computer with the following contents in it:

Note that there need to be no blank line(s) or whitespace(s) before the xml statement. if you permit them, the following error message takes place while executing the ant build -

The processing instruction target matching "[xX][mM][lL]" is not allowed. All construct files require the project detail and at least one Target element.

The XML detail project has three attributes :




The Name of the project. (Optional)


The default target for the build script. A project may contain any number of targets. This attribute specifies which target should be considered as the default. (Mandatory)


The base directory (or) the root folder for the project. (Optional)

A goal is a set of tasks which you want to run as one unit. In our example, we have a easy target to offer an informational message to the user.

Targets may have dependencies on other targets. for instance, a deploy target may also have a dependency at the package goal, the package goal may also have a dependency at the compile goal and so on. Dependencies are denoted using the depends attribute. for example:

The target element has the following attributes:




The name of the target (Required)


Comma separated list of all targets that this target depends on. (Optional)


A short description of the target. (optional)


Allows the execution of a target based on the trueness of a conditional attribute. (optional)


Adds the target to the dependency list of the specified Extension Point. An Extension Point is similar to a target, but it does not have any tasks. (Optional)

The echo project within the above example is a trivial project that prints a message. In our example, it prints the message hello world.

To run the ant build report, open up command prompt and navigate to the folder where the build.xml resides, and type ant info. you may also type ant instead. each will work, because info is the default target within the build file. You must see the following output:

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Apache Ant Topics