Cover image for Ant: The Definitive Guide, 2nd Edition

Book description

Soon after its launch, Ant succeeded in taking the Java world by storm, becoming the most widely used tool for building applications in Java environments. Like most popular technologies, Ant quickly went through a series of early revision cycles. With each new version, more functionality was added, and more complexity was introduced. Ant evolved from a simple-to-learn build tool into a full-fledged testing and deployment environment. Ant: The Definitive Guide has been reworked, revised and expanded upon to reflect this evolution. It documents the new ways that Ant is being applied, as well as the array of optional tasks that Ant supports. In fact, this new second edition covers everything about this extraordinary build management tool from downloading and installing, to using Ant to test code. Here are just of a few of the features you'll find detailed in this comprehensive, must-have guide:

  • Developing conditional builds, and handling error conditions

  • Automatically retrieving source code from version control systems

  • Using Ant with XML files

  • Using Ant with JavaServer Pages to build Web applications

  • Using Ant with Enterprise JavaBeans to build enterprise applications

Far exceeding its predecessor in terms of information and detail, Ant: The Definitive Guide, 2nd Edition is a must-have for Java developers unfamiliar with the latest advancements in Ant technology. With this book at your side, you'll soon be up to speed on the premiere tool for cross-platform development. Author Steve Holzner is an award-winning author who s been writing about Java topics since the language first appeared; his books have sold more than 1.5 million copies worldwide.

Table of Contents

  1. Ant: The Definitive Guide, 2nd Edition
  2. A Note Regarding Supplemental Files
  3. Preface
    1. What's Inside
    2. Conventions Used in This Book
    3. What You'll Need
    4. Using Code Examples
    5. We'd Like to Hear from You
  4. 1. Getting Started
    1. 1.1. Ant's Origins
    2. 1.2. Getting Ant
      1. 1.2.1. Installing Ant
      2. 1.2.2. Testing Ant
    3. 1.3. Ant at Work
    4. 1.4. Anatomy of a Build File
      1. 1.4.1. Projects
      2. 1.4.2. Targets
      3. 1.4.3. Tasks
        1. 1.4.3.1. Built-in tasks
        2. 1.4.3.2. Optional tasks
      4. 1.4.4. Dependent Tasks
      5. 1.4.5. Properties
        1. 1.4.5.1. Property attributes
        2. 1.4.5.2. Built-in properties
    5. 1.5. Running Ant
      1. 1.5.1. Command-Line Options
      2. 1.5.2. Executing Ant
      3. 1.5.3. Customizable Environment Variables
      4. 1.5.4. Failed Builds
      5. 1.5.5. Verbose Output
      6. 1.5.6. Logging and Libraries
  5. 2. Using Properties and Types
    1. 2.1. Using Properties to Control Tasks
      1. 2.1.1. Setting Conditions
      2. 2.1.2. Performing Conditional Actions
      3. 2.1.3. Stopping Builds
      4. 2.1.4. Property-Setting Tasks
        1. 2.1.4.1. Availability of resources
        2. 2.1.4.2. Checking file modification dates
    2. 2.2. Using Property Files
      1. 2.2.1. Loading Text
      2. 2.2.2. Overriding Properties
      3. 2.2.3. Setting Properties Using Environment Variables
    3. 2.3. Handling Data Using Types
      1. 2.3.1. Path-Like Structures
      2. 2.3.2. Working with Groups of Files
        1. 2.3.2.1. Default excludes
      3. 2.3.3. Working with Groups of Directories
      4. 2.3.4. Creating Lists of Files
      5. 2.3.5. Working with Patterns
      6. 2.3.6. Selectors
      7. 2.3.7. File Filters
        1. 2.3.7.1. Using the filter task
      8. 2.3.8. Filtering and Modifying Text with FilterChains and FilterReaders
      9. 2.3.9. Transforming One Set of Files to Another with Mappers
  6. 3. Building Java Code
    1. 3.1. Compiling Code
      1. 3.1.1. Compiling Source Files
        1. 3.1.1.1. Selecting which files to compile
        2. 3.1.1.2. Forking the compiler
      2. 3.1.2. Setting Command-Line Options
      3. 3.1.3. Using a Different Java Compiler
    2. 3.2. Getting Input from the User
    3. 3.3. Calling Other Ant Tasks
      1. 3.3.1. Calling Ant Tasks in the Same Build File
      2. 3.3.2. Calling Ant Tasks in Other Build Files
    4. 3.4. Importing Other Build Files
    5. 3.5. Documenting Code
    6. 3.6. Creating JAR Files
      1. 3.6.1. Working with the META-INF Directory
      2. 3.6.2. Creating Manifest Files
    7. 3.7. Setting Build Numbers
    8. 3.8. Setting Timestamps
  7. 4. Deploying Builds
    1. 4.1. Packaging Applications for Deployment
      1. 4.1.1. Creating TAR Files
      2. 4.1.2. Compressing Using gzip and bzip2
      3. 4.1.3. Creating ZIP Files
      4. 4.1.4. Fixing Carriage Returns
      5. 4.1.5. Checking File Contents Using Checksums
      6. 4.1.6. Setting Creation Time and Date
    2. 4.2. Preparing to Deploy
      1. 4.2.1. Deleting Existing Files
      2. 4.2.2. Creating New Directories
    3. 4.3. Deploying Applications
      1. 4.3.1. Deploying by Copying
      2. 4.3.2. Moving Files
      3. 4.3.3. Deploying Remotely Using FTP
      4. 4.3.4. Deploying Remotely Using Telnet
      5. 4.3.5. Deploying Remotely Using SSH
      6. 4.3.6. Deploying Remotely Through Email
      7. 4.3.7. Setting File Protections with chmod
    4. 4.4. Scheduling Automatic Builds
      1. 4.4.1. Unix
      2. 4.4.2. Windows
      3. 4.4.3. Anthill
      4. 4.4.4. Cruise Control and Gump
  8. 5. Testing Builds with JUnit
    1. 5.1. Using JUnit
      1. 5.1.1. Writing the Tests
      2. 5.1.2. Performing Tests with the junit Task
        1. 5.1.2.1. Formatting test results
        2. 5.1.2.2. Specifying the test class
        3. 5.1.2.3. Running tests in batches
    2. 5.2. Running Test Cases
      1. 5.2.1. Using the Plain Formatter for Reports
      2. 5.2.2. Using the Brief Formatter for Reports
      3. 5.2.3. Using the XML Formatter for Reports
      4. 5.2.4. Creating Reports with the junitreport Task
    3. 5.3. Testing in Batches
    4. 5.4. Running the Build File
    5. 5.5. Extending JUnit
  9. 6. Getting Source Code from CVS Repositories
    1. 6.1. Source Control and Ant
    2. 6.2. Logging In
    3. 6.3. Working with the Server
      1. 6.3.1. Checking Out Modules
      2. 6.3.2. Updating Shared Code
      3. 6.3.3. Committing Source Code
      4. 6.3.4. Comparing Files
    4. 6.4. Getting Version Data
    5. 6.5. Creating Change Logs
    6. 6.6. Finding Changes Between Versions
    7. 6.7. Creating Patches
  10. 7. Executing External Programs
    1. 7.1. Executing Java Code
      1. 7.1.1. Handling Errors and Return Codes
    2. 7.2. Executing External Programs
      1. 7.2.1. Handling Return Codes
      2. 7.2.2. Targeting Operating Systems
      3. 7.2.3. Handling Timeouts
      4. 7.2.4. Executing Shell Commands
      5. 7.2.5. Checking for External Programs Before Executing Them
    3. 7.3. Performing Batch Execution
    4. 7.4. Multithreading Tasks
    5. 7.5. Setting Execution Order
  11. 8. Developing for the Web
    1. 8.1. Creating WAR Archives
    2. 8.2. Creating CAB Files
    3. 8.3. Creating Simple Web Deployment
    4. 8.4. Deploying with SCP
    5. 8.5. Deploying to Tomcat
    6. 8.6. Deploying to Tomcat
    7. 8.7. Compiling JSPs
    8. 8.8. Deploying to EJB Containers
      1. 8.8.1. Creating EAR Files
      2. 8.8.2. Supporting Hot Deployment
        1. 8.8.2.1. The generic element
        2. 8.8.2.2. The weblogic element
        3. 8.8.2.3. The jonas element
  12. 9. XML and XDoclet
    1. 9.1. Validating XML Documents
      1. 9.1.1. Validating with XML Schema
      2. 9.1.2. Validating with DTDs
    2. 9.2. Loading Properties from XML Files
    3. 9.3. Creating Ant Task DTDs
    4. 9.4. Transforming XML Using XSLT
    5. 9.5. Using XDoclet
      1. 9.5.1. Developing Applications
      2. 9.5.2. Working with EJB Containers
    6. 9.6. Developing Enterprise JavaBeans
      1. 9.6.1. JARing Files
  13. 10. Optional Tasks
    1. 10.1. Using Sound
    2. 10.2. Creating Splash Screens
    3. 10.3. Subtituting Text Using Regular Expressions
    4. 10.4. Handling Dependencies
  14. 11. Integrating Ant with Eclipse
    1. 11.1. Introducing Eclipse
      1. 11.1.1. Getting Eclipse
      2. 11.1.2. Creating an Eclipse Project
      3. 11.1.3. Writing an Ant Build File in Eclipse
    2. 11.2. Running Ant Build Files
      1. 11.2.1. Selecting the Build File and Passing Arguments to Ant
      2. 11.2.2. Modifying the Ant Classpath
      3. 11.2.3. Setting Property Values
      4. 11.2.4. Setting Environment Variables
      5. 11.2.5. Configuring the Ant Editor
      6. 11.2.6. Adding New Ant Tasks and Types
    3. 11.3. Using a Different Version of Ant
    4. 11.4. Using the Ant View
  15. 12. Extending Ant
    1. 12.1. Creating a Simple Custom Ant Task
    2. 12.2. Extending the Task Class
      1. 12.2.1. The Task Life Cycle
      2. 12.2.2. Accessing the Project and Properties in Code
      3. 12.2.3. Handling Attributes in Custom Tasks
      4. 12.2.4. Making Builds Fail
      5. 12.2.5. Handling Nested Text
      6. 12.2.6. Handling Nested Elements
      7. 12.2.7. Using Filesets
      8. 12.2.8. Running External Programs
      9. 12.2.9. Running Scripts
    3. 12.3. Creating Custom Listeners
    4. 12.4. Creating Custom Loggers
    5. 12.5. Creating Custom Filters
    6. 12.6. Creating Custom Selectors
    7. 12.7. Creating New Types
  16. About the Author
  17. Colophon
  18. Copyright