Apache Ant Tutorial - Build Files
Tutorial Name: Apache Ant Tutorial - Build Files
Category: PC Miscellaneous
Submitted By: Timezone
Typically, Ant's build file, called build.xml should reside in the base directory of the project. However there is no restriction on the file name or its location. You are free to use other file names or save the build file in some other location.
For this exercise, create a file called build.xml anywhere in your computer with the following contents in it
<?xml version = "1.0"?>
<project name = "Hello World Project" default = "info">
<target name = "info">
<echo>Hello World - Welcome to Apache Ant!</echo>
Note that there should be no blank line(s) or whitespace(s) before the xml declaration. If you allow them, the following error message occurs while executing the ant build -
The processing instruction target matching "[xX][mM][lL]" is not allowed.
All build files require the project element and at least one target element.
The XML element 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 target is a collection of tasks that you want to run as one unit. In our example, we have a simple target to provide an informational message to the user.
Targets can have dependencies on other targets. For example, a deploy target may have a dependency on the package target, the package target may have a dependency on the compile target and so forth. Dependencies are denoted using the depends attribute. For example
<target name = "deploy" depends = "package">
<target name = "package" depends = "clean,compile">
<target name = "clean" >
<target name = "compile" >
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 task in the above example is a trivial task that prints a message. In our example, it prints the message Hello World.
To run the ant build file, open up command prompt and navigate to the folder where the build.xml resides, and type ant info. You could also type ant instead. Both will work, because info is the default target in the build file. You should see the following output
info: [echo] Hello World - Welcome to Apache Ant!
Total time: 0 seconds
- 01. Apache POI PPT Tutorial - Jav... (24)
- 02. Apache POI PPT Tutorial - Cla... (25)
- 03. Apache POI PPT Tutorial - Pre... (23)
- 04. Apache Ant Tutorial - JUnit I... (39)
- 05. Apache Ant Tutorial - Build D... (36)
- 06. Apache Ant Tutorial - Extendi... (33)
- 07. Apache Ant Tutorial - Eclipse... (36)
- 08. Apache Ant Tutorial - Executi... (26)
- 09. Apache Ant Tutorial - Deployi... (32)
- 10. Apache Ant Tutorial - Packagi... (30)
- 11. Apache Ant Tutorial - Creatin... (55)
- 12. XAMPP reaching the max SQL si... (78)
- 13. HOW TO GET CUSTOM AND ANIMAT... (124)
- 14. How to Overclock your Monito... (323)
- 15. Restoring Windows Photo View... (698)