Ant in Action


This second edition of a Manning bestseller has been revised and re-titled to fit the 'In Action' Series by Steve Loughran, an Ant project committer. Ant in Action introduces Ant and how to use it for test-driven Java application development. Ant itself is moving to v1.7, a major revision, at the end of 2006 so the timing for the book is right. A single application of increasing complexity, followed throughout the book, shows how an application evolves and how to handle the problems of building and testing. ...

See more details below
Paperback (Second Edition)
$34.65 price
(Save 30%)$49.99 List Price
Other sellers (Paperback)
  • All (19) from $2.61   
  • New (9) from $28.32   
  • Used (10) from $2.61   
Sending request ...


This second edition of a Manning bestseller has been revised and re-titled to fit the 'In Action' Series by Steve Loughran, an Ant project committer. Ant in Action introduces Ant and how to use it for test-driven Java application development. Ant itself is moving to v1.7, a major revision, at the end of 2006 so the timing for the book is right. A single application of increasing complexity, followed throughout the book, shows how an application evolves and how to handle the problems of building and testing. Reviewers have praised the book's coverage of large-projects, Ant's advanced features, and the details and depth of the discussion-all unavailable elsewhere.

This is a major revision with the second half of the book completely new, including:

  • How to Manage Big projects
  • Library management
  • Enterprise Java
  • Continuous integration
  • Deployment
  • Writing new Ant tasks and datatypes

Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book.

Read More Show Less

Product Details

  • ISBN-13: 9781932394801
  • Publisher: Manning Publications Company
  • Publication date: 7/28/2007
  • Edition description: Second Edition
  • Edition number: 2
  • Pages: 600
  • Sales rank: 797,328
  • Product dimensions: 7.41 (w) x 9.32 (h) x 1.19 (d)

Meet the Author

Steve Loughran has been an active user and developer of Ant since the year 2000, a committer on the project since 2001, and a member of the Apache Software Foundation since 2004. He regularly lectures on the problems of big-system builds, distributed testing, and deployment. He is a research scientist at Hewlett-Packard Laboratories in Bristol, UK.

Read More Show Less

Table of Contents

Preface to the second edition     xix
Foreword to the first edition     xxi
Preface to the first edition     xxiii
Acknowledgments     xxv
About this book     xxvii
About the authors     xxxi
About the cover illustration     xxxii
Introduction to the Second Edition     1
Learning Ant     3
Introducing Ant     5
What is Ant?     5
The core concepts of Ant     6
Ant in action: an example project     8
What makes Ant so special?     11
When to use Ant     12
When not to use Ant     13
Alternatives to Ant     13
IDEs     13
Make     14
Maven     16
The ongoing-evolution of Ant     16
Summary     17
A first Ant build     19
Defining our first project     19
Step zero: creating the project directory     20
Step one: verifying the tools are in place     20
Step two: writing your first Ant build file     21
Examining the build file     21
Step three: running your first build     23
If the buildfails     23
Looking at the build in more detail     25
Step four: imposing structure     27
Laying out the source directories     28
Laying out the build directories     29
Laying out the distribution directories     29
Creating the build file     31
Target dependencies     32
Running the new build file     33
Incremental builds     34
Running multiple targets on the command line     35
Step five: running our program     36
Why execute from inside Ant?     36
Adding an "execute" target     37
Running the new target     38
Ant command-line options     39
Specifying which build file to run     40
Controlling the amount of information provided     41
Coping with failure     42
Getting information about a project     42
Examining the final build file     43
Running the build under an IDE     44
Summary     45
Understanding Ant datatypes and properties     47
Preliminaries     48
What is an Ant datatype?     48
Property overview     48
Introducing datatypes and properties with [left angle bracket]javac[right angle bracket]     49
Paths     52
How to use a path     53
Filesets     53
Patternsets     54
Selectors     58
Additional Ant datatypes     59
Properties     61
Setting properties with the [left angle bracket]property[right angle bracket] task     62
Checking for the availability of files: [left angle bracket]available[right angle bracket]     66
Testing conditions with [left angle bracket]condition[right angle bracket]     67
Creating a build timestamp with [left angle bracket]tstamp[right angle bracket]     69
Setting properties from the command line     70
Controlling Ant with properties     70
Conditional target execution     71
Conditional build failure     72
Conditional patternset inclusion/exclusion     72
References     73
Viewing datatypes     73
Managing library dependencies     75
Resources: Ant's secret data model     76
Best practices     76
Summary     77
Testing with JUnit     79
What is testing, and why do it?     80
Introducing our application     81
The application: a diary     81
How to test a program     83
Introducing JUnit     84
Writing a test case     86
Running a test case     86
Asserting desired results     87
Adding JUnit to Ant     90
Writing the code     92
The JUnit task: [left angle bracket]junit[right angle bracket]     93
Fitting JUnit into the build process     94
Halting the build when tests fail     96
Viewing test results     96
Running multiple tests with [left angle bracket]batchtest[right angle bracket]     98
Generating HTML test reports     99
Halting the builds after generating reports     101
Advanced [left angle bracket]junit[right angle bracket] techniques     102
Best practices     106
The future of JUnit     107
Summary     108
Packaging projects     110
Working with files     111
Deleting files     112
Copying files     113
Moving and renaming files     114
Introducing mappers     114
Modifying files as you go     119
Preparing to package      120
Adding data files to the classpath     121
Generating documentation     122
Patching line endings for target platforms     124
Creating JAR files     126
Testing the JAR file     128
Creating JAR manifests     129
Adding extra metadata on the JAR     131
JAR file best practices     132
Signing JAR files     132
Testing with JAR files     135
Creating Zip files     136
Creating a binary Zip distribution     137
Creating a source distribution     138
Zip file best practices     139
Packaging for Unix     139
Tar files     139
Generating RPM packages     143
Working with resources     143
A formal definition of a resource     143
What resources are there?     144
Resource collections     145
Summary     147
Executing programs     149
Running programs under Ant-an introduction     149
Introducing the [left angle bracket]java[right angle bracket] task     151
Setting the classpath     152
Arguments     153
Defining system properties      155
Running the program in a new JVM     156
JVM tuning     157
Handling errors     158
Executing JAR files     160
Running native programs     161
Running our diary as a native program     162
Executing shell commands     162
Running under different Operating Systems     163
Probing for a program     166
Advanced [left angle bracket]java[right angle bracket] and [left angle bracket]exec[right angle bracket]     167
Setting environment variables     167
Handling timeouts     168
Running a program in the background     169
Input and output     170
Piped I/O with an I/O redirector     171
FilterChains and FilterReaders     172
Bulk operations with [left angle bracket]apply[right angle bracket]     174
How it all works     176
[left angle bracket]java[right angle bracket]     176
[left angle bracket]exec[right angle bracket] and [left angle bracket]apply[right angle bracket]     177
Best practices     177
Summary     178
Distributing our application     179
Preparing for distribution     180
Securing our distribution     181
Server requirements     183
FTP-based distribution of a packaged application     183
Uploading to Unix     184
Uploading to a Windows FTP server     185
Uploading to SourceForge     186
FTP dependency logic     187
Email-based distribution of a packaged application     188
Sending HTML messages     191
Secure distribution with SSH and SCP     192
Uploading files with SCP     193
Downloading files with [left angle bracket]scp[right angle bracket]     195
Remote execution with [left angle bracket]sshexec[right angle bracket]     197
Troubleshooting the SSH tasks     197
HTTP download     198
How to probe for a server or web page     199
Fetching remote files with [left angle bracket]get[right angle bracket]     200
Performing the download     201
Distribution over multiple channels     203
Calling targets with [left angle bracket]antcall[right angle bracket]     203
Distributing with [left angle bracket]antcall[right angle bracket]     206
Summary     208
Putting it all together     209
How to write good build files      209
Building the diary library     210
Starting the project     210
The public entry points     211
Setting up the build     212
Compiling and testing     216
Packaging and creating a distribution     218
Distribution     222
Adopting Ant     225
Building an existing project under Ant     228
Summary     230
Applying Ant     231
Beyond Ant's core tasks     233
The many different categories of Ant tasks     234
Installing optional tasks     236
Troubleshooting     238
Optional tasks in action     239
Manipulating property files     239
Improving [left angle bracket]javac[right angle bracket] with dependency checking     241
Software configuration management under Ant     243
Using third-party tasks     245
Defining tasks with [left angle bracket]taskdef[right angle bracket]     246
Declaring tasks defined in property files     247
Defining tasks into a unique namespace     248
Defining tasks from an Antlib     249
The Ant-contrib tasks     250
The Ant-contrib tasks in action      253
Code auditing with Checkstyle     259
Summary     263
Working with big projects     264
Master builds: managing large projects     265
Introducing the [left angle bracket]ant[right angle bracket] task     266
Designing a scalable, flexible master build file     268
Controlling child project builds     270
Setting properties in child projects     270
Passing down properties and references in [left angle bracket]ant[right angle bracket]     272
Advanced delegation     275
Getting data back     276
Inheriting build files through [left angle bracket]import[right angle bracket]     277
XML entity inclusion     277
Importing build files with [left angle bracket]import[right angle bracket]     278
How Ant overrides targets     279
Calling overridden targets     280
The special properties of [left angle bracket]import[right angle bracket]     281
Applying [left angle bracket]import[right angle bracket]     283
Extending an existing build file     283
Creating a base build file for many projects     284
Mixin build files     286
Best practices with [left angle bracket]import[right angle bracket]      287
Ant's macro facilities     288
Redefining tasks with [left angle bracket]presetdef[right angle bracket]     288
The hazards of [left angle bracket]presetdef[right angle bracket]     290
Writing macros with [left angle bracket]macrodef[right angle bracket]     291
Passing data to a macro     292
Local variables     294
Effective macro use     295
Summary     296
Managing dependencies     297
Introducing Ivy     299
The core concepts of Ivy     299
Installing Ivy     301
Configuring Ivy     302
Resolving, reporting, and retrieving     304
Creating a dependency report     305
Retrieving artifacts     306
Setting up the classpaths with Ivy     307
Working across projects with Ivy     308
Sharing artifacts between projects     308
Using published artifacts in other projects     310
Using Ivy to choreograph builds     313
Other aspects of Ivy     315
Managing file versions through Ivy variables     315
Finding artifacts on the central repository     316
Excluding unwanted dependencies     317
Private repositories     317
Moving to Ivy     318
Summary     318
Developing for the Web     320
Developing a web application     321
Writing a feed servlet     323
Libraries in web applications     324
Writing web pages     325
Creating a web.xml file     327
Building the WAR file     328
Deployment     329
Deployment by copy     330
Post-deployment activities     331
Probing for server availability     331
Pausing the build with [left angle bracket]sleep[right angle bracket]     333
Testing web applications with HttpUnit     333
Writing HttpUnit tests     334
Compiling the HttpUnit tests     337
Running the HttpUnit tests     338
Summary     339
Working with XML     340
Background: XML-processing libraries     341
Writing XML     341
Validating XML     343
Validating documents using DTD files     345
Validating documents with XML Schema     347
Validating RelaxNG documents     349
Reading XML data     352
Transforming XML with XSLT     353
Defining the structure of the constants file     354
Creating the constants file     355
Creating XSL style sheets     355
Initializing the build file     358
Summary     362
Enterprise Java     363
Evolving the diary application     364
Making an Enterprise application     365
Creating the beans     366
Compiling Java EE-annotated classes     368
Adding a session bean     369
Extending the web application     371
Building the Enterprise application     373
Deploying to the application server     378
Server-side testing with Apache Cactus     378
Writing a Cactus test     379
Building Cactus tests     380
The Cactus Ant tasks     381
Adding Cactus to an EAR file     382
Running Cactus tests     383
Diagnosing EJB deployment problems     384
Summary     385
Continuous integration     387
Introducing continuous integration     388
What do you need for continuous integration?     390
Luntbuild     391
Installing Luntbuild      393
Running Luntbuild     393
Configuring Luntbuild     394
Luntbuild in action     400
Review of Luntbuild     401
Moving to continuous integration     402
Summary     404
Deployment     406
How to survive deployment     407
Deploying with Ant     410
Database setup in Ant     411
Creating and configuring a database from Ant     412
Issuing database administration commands     413
Deploying with SmartFrog     415
SmartFrog: a new way of thinking about deployment     415
The concepts in more detail     417
The SmartFrog components     425
Using SmartFrog with Ant     426
Deploying with SmartFrog     428
Deploying with the [left angle bracket]deploy[right angle bracket] task     433
Summary of SmartFrog     435
Embracing deployment     436
Summary     438
Extending Ant     441
Writing Ant tasks     443
What exactly is an Ant task?     444
The life of a task     445
Introducing Ant's Java API     446
Ant's utility classes      451
A useful task: [left angle bracket]filesize[right angle bracket]     453
Writing the task     453
How Ant configures tasks     455
Configuring the [left angle bracket]filesize[right angle bracket] task     457
Testing tasks with AntUnit     458
Using AntUnit     458
Testing the [left angle bracket]filesize[right angle bracket] task     460
Running the tests     461
More task attributes     463
Enumerations     463
User-defined types     465
Supporting nested elements     465
Working with resources     467
Using a resource-enabled task     470
Delegating to other tasks     471
Setting up classpaths in a task     472
Other task techniques     476
Making an Antlib library     478
Summary     481
Extending Ant further     483
Scripting within Ant     484
Writing new tasks with [left angle bracket]scriptdef[right angle bracket]     486
Scripting summary     489
Conditions     490
Writing a conditional task     492
Writing a custom resource     493
Using a custom resource      496
How Ant datatypes handle references     496
Selectors     497
Scripted selectors     499
Developing a custom mapper     499
Implementing a custom filter     501
Handling Ant's input and output     503
Writing a custom listener     505
Writing a custom logger     509
Using loggers and listeners     511
Handling user input with an InputHandler     512
Embedding Ant     512
Summary     514
Installation     516
Before you begin     516
The steps to install Ant     517
Setting up Ant on Windows     517
Setting up Ant on Unix     518
Installation configuration     520
Troubleshooting installation     520
XML Primer     525
XML namespaces     529
IDE Integration     531
How IDEs use Ant     531
Eclipse     533
Sun NetBeans     539
IntelliJ IDEA     543
Building with Ant and an IDE     546
Index     549
Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)