Chapter 2. Using Properties and Types

In Chapter 1, you learned about properties and tasks in Ant. However, long tables with short descriptions do not an Ant expert make. In this chapter, you begin to get the details on using Ant's extensive feature set, which relies on two conerstones: properties and types. You received an introduction to them in the previous chapter, but here's where to get a real working knowledge.

In the examples from last chapter, building was a linear process: you compiled some files, you JARred them up, and then you were done. In the real world, things are almost never so straightforward. You need to be able to check for specific files and perform different tasks depending on the existence of those files. You need to respond to error conditions, and let the user know what has happened when errors do occur. You often need to deal with groups of files, copy them over en masse, and more. These kinds of tasks involve using properties and types.

Using Properties to Control Tasks

Ant provides extensive support for controlling the build process; though Ant is not a programming language, it has a number of control structures, and those control structures rely on properties. As if and try/catch allow you to handle several logic paths in Java, Ant's control tasks allow you the same flexibility within the context of a build process.

Setting Conditions

The foundation to any type of control processing is some form of the if statement. This typically involves two steps: ...

Get Ant: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.