Java Tutorial - Java Script :
Build Tools: Ant
Ant is new kind of build tool. Ant uses XML configuration files to describe the project to be built. Instead of executing shell commands, Ant executes Java classes. The following table summarizes Ant.
After the files are downloaded, unzip them into the directory where you want Ant installed. If you are using Windows 98/Me, you we suggest that you install Ant into a directory with a short pathname such as C:\ant to avoid
issues with filename mangling in the Windows 98/Me command line. You will want to create an environment variable ANT_HOME and add the %ANT_HOME%\bin directory to your path. Under Windows 98/Me, adding
the following line to the autoexec.bat file can do this:
set ANT_HOME=c:\ant
PATH %PATH%;c:\ant\bin
In other versions of Windows, you can do this via the System icon in the Control Panel. Under Linux (and Bash) you can do this by adding the following line to the profile in the user’s home directory:
ANT_HOME=/usr/local/java/ant;export ANT_HOME
PATH= $PATH:/usr/local/java/ant/bin
This assumes that Ant was installed into /usr/local/java/ant directory on your Linux machine
After Ant is properly installed, it can be executed by using the build command. build is a batch file on Windows or a shell script under Linux that sets the environment variables and launches the Java runtime.
Ant uses XML files to control the build process. Normally, an Ant build file is named build.xml. The root element of the build file is the project element.
The primary elements are:
Project . The project is the root element of an Ant build file. The project identifies the default target and the base directory used for the build.
Target. A target is something that can be built or done within a project. Targets may include things like generating directory structures, compiling Java code, or deleting old class files. A project may have many targets. Targets can have dependencies on other targets, forcing a target to wait to be built until the targets it depends on have been built.
Task . A task is not the actual element name but rather describes a class of elements. Tasks are pieces of code that can be executed. These are the commands or operations that are used to build targets. Ant has many
built-in tasks including Copy, Zip, and Javac. New tasks can be added and are written in Java.
Property. Properties are similar to variables. Properties are named and have values. Properties can be expanded within attributes of other tags. Properties can exist outside of a target.
A more detailed look at Ant syntax is beyond the scope of this chapter; however, Ant is revisited in later chapters, where it is used to compile the code examples in the book.
If you are planning to use open source tools and you want to be able to rebuild them, Ant is not an option, it is a requirement. Ant is also required for running some tools. Ant is so pervasive for open source Java that support for
Ant is built into almost every Java development tool, commercial and open source. Ant support is provided for all of the editors and IDEs discussed in this chapter.
