Chapter 4: Ant Primer


Overview

This chapter is an introduction to the fundamental concepts and techniques involved in using Ant to achieve continuous integration on your projects. Ant is a build tool that enables you to automate the build process. In that respect, Ant is similar to the make tool; but unlike make, Ant was designed specifically for Java development. Ant is written in Java, so it works across platforms and does not rely on shell-specific commands that vary greatly in function and usage from operating system to operating system. Instead, Ant relies on the Java platform to perform file access, compilation, and other tasks you need to build your Java projects.

start sidebar
Where To Get Ant

Ant was developed by The Apache Software Foundation as part of their Jakarta project. Ant 1.6.1 is distributed with The Apache Software License, Version 2.0 and can be downloaded at:

http://ant.apache.org/bindownload.cgi

end sidebar
 

A major advantage of Ant is its extensibility. Ant is easily extensible using cross-platform Java classes. You can also extend Ant by writing custom Java tasks and using the scripting task, which works with JavaScript (Rhino), Python, NetRexx, and others. In addition, if you must, you can call out to shell scripts, OS executables, and OS commands with the Ant exec task. Then, later, you can write a cross-platform version of the task in Java or with the Ant scripting task, which uses XML for its syntax.

The build-and-deploy cycle should be automated so you don't incorporate operator error. Writing a build script also documents the build process. Documentation becomes critical when a developer leaves your company. By using Ant, your company retains the knowledge needed to deploy the system, because the build-and-deploy process is automated by an Ant script (called a buildfile) and not locked away in the departed developer's IDE (which was set up for his local development environment). Another benefit of using Ant is that the script that automates the build-and-deploy process in effect also documents that process; unlike most IDEs' binary project configuration files, an Ant buildfile is written in human-readable text.

start sidebar
What Is Your Favorite IDE?

Ant complements Integrated Development Environments (IDEs); Ant does not replace IDEs, nor do IDEs replace Ant. IDEs can greatly simplify Java development, but they are not good for automating the build-and-deploy process of a complex project. Every software process needs a repeatable build system, and IDEs do not provide such a system.

Developers become attached to the IDE they use. At our company, we use several different IDEs, including Eclipse, Borland JBuilder, NetBeans, Forte CE, Visual Age for Java, JDE (Java development environment for Emacs), and Ultra Edit. Ant reduces the potential havoc by providing a standard on which to base our build-and-deploy process.

end sidebar
 

You can use Ant for the organization of deployment and for automated builds. Ant supports the concept of continuous integration , as described in the next section. Using Ant to perform continuous integration changes the whole development blueprint of your project. With a little discipline and setup time, continuous integration reduces problems linked with team development.

Developers often talk about automated building and testing but seldom implement it. Ant makes automated building and testing possible and plausible. Ant and JUnit combine well to allow teams to build and test their software several times a day. Such an automated process is worth the sweat. You will find out who broke what sooner ”before you forget who did what. You will find integration bugs before they become strange and unpredictable.

Alternatives to Ant exist. However, Ant has become the de facto standard for automating Java builds. For example, Sun's pet store J2EE blueprint application uses Ant. The other day, we went to the Orion application server site to look at some examples, and all of them had corresponding Ant buildfiles. Of course, many of the projects at Apache's Jakarta have Ant buildfiles . Ant is popular because it is easy to learn and extend. In addition, several IDEs and development tools support Ant ”for example, the NetBeans IDE and Together Control Center.

The next section will cover the mechanics of using Ant to create buildfiles.




Professional Java Tools for Extreme Programming
Professional Java Tools for Extreme Programming: Ant, XDoclet, JUnit, Cactus, and Maven (Programmer to Programmer)
ISBN: 0764556177
EAN: 2147483647
Year: 2003
Pages: 228

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net