Ant - The Definitive Guide 205
Ant The Definitive Guide | |
author | Steve Holzner |
pages | 316 |
publisher | O'Reilly |
rating | 8 |
reviewer | Pankaj Kumar |
ISBN | 0596006098 |
summary | Complete Build Management for Java with Ant |
As a long time Ant user, I have written many Ant build scripts, automating my builds and speeding up the overall development cycle, mostly relying on its excellent online documentation. As a Java developer, I have admired its simple and intuitive interface and the modular design. So on getting Ant: The Definitive Guide in my hands I wasn't expecting a whole lot new to learn, and thought of using it only as a reference book.
After having the book on my desk for more than a month, though, and occasionally flipping through its pages whenever I would otherwise have consulted the online documentation, I must say that I had been missing out on some very important things: tasks like ftp and war deployment that I was simply not aware of and had never felt the need to look up, but could very well use. The other interesting thing I noticed was that my build scripts became smaller, more modular and easier to read.
Like most books in the The Definitive Guide series, Ant The Definitive Guide assumes a certain level of familiarity with underlying technologies such as Java and XML and focuses on providing complete, reference like details of Ant features and tasks. These description are generously supplemented with examples and code fragments.
But so is the the online documentation for Ant! Will someone gain additional insight in using Ant, or be able to work faster, or make better use of Ant capabilities, by consulting this book, instead of the online documentation for a particular Ant task? To find the answer, I randomly picked two topics -- filesets, an important and oft-used Ant datatype, and javac, a core Ant task -- and compared their online description with the one in the book. Here is what I found.
Besides the datatype definition, explanation of various attributes, sub-elements, and the examples, the book also covers how to specify conditional inclusion or exclusion of certain filename patterns when a property is set (or unset). Though this can be inferred from online documentation by a determined user, this particular use is far from obvious. The coverage in the book also talks about the relationship of the fileset datatype with the javac task, pointing out that the fileset attribute dir is equivalent of javac attribute srcdir, as attribute dir will be confusing in javac: is it referring to source directory or destination directory. This is the kind of insight that really helps a user.
The treatment of the javac task in the book is not much different from the one in the online documentation. Both have almost the same material, though the information in the book is better organized for new users. On the other hand, I found the online documentation to be more complete, especially with respect to the compiler specific options and behavior idiosyncrasies.
Here is a rundown on what the book covers: Chapter 1, Getting Started is a quick primer on Ant, with sufficient details for a new user to start using Ant for very simple build tasks. Chapter 2, Using Properties and Types introduces the building block tasks and datatypes, such as property, condition, fileset, path like structures, selectors and so on, used in other Ant tasks. Chapter 3, Building Java Code covers the tasks and activities around compiling Java source files (ie; javac), organizing the build steps in various targets within a single build scripts and/or across multiple scripts, generating documentation using javadoc and creating distribution jars and zip files. The rest of the chapters are devoted to tasks for specific purposes, such as launching external programs (Chapter 7, Executing External Programs), copying files and manipulating directories either on the same machine or over the network (Chapter 4, Deploying Builds), running JUnit tests (Chapter 5, Testing Builds with JUnit) and so on. There are also separate chapters covering interaction of Ant with XML and XDoclet (Chapter 9, XML and XDoclet) and with Eclipse (Chapter 11, Integrating Ant with Eclipse). The last chapter, Chapter 12, Extending Ant, talks about extending Ant by doing things like adding your own tasks, creating custom filters, writing your own build listeners and loggers etc. This chapter also has a small section on how to embed a script written in one of the supported scripting languages within an Ant script.
As you can see from this outline, the book covers almost everything that is to know about Ant and other related software.
So, what is not so good about this book? Well, I didn't find anything wrong with the topics which are actually covered by the book. Of course, there are additional things that I would have liked to see in the book: (a) A good sample Ant script which could be used as the starting point for most small to medium-sized projects; (b) A more thorough explanation of how dependencies among targets determine the execution sequence and how this fits in with explicit invocation of targets; and (c) pictures to illustrate some of the concepts such as life cycle of an Ant task, selection of files in a fileset and the dependency tree of targets.
Overall, I found the book to be comprehensive, well organized, easy to read and good value for money.
You can purchase Ant: The Definitive Guide from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Make file (Score:2, Informative)
Save Money (Score:0, Informative)
Bookpool has it cheaper than bn.com (Score:3, Informative)
Re:Make file (Score:3, Informative)
SCons (Score:5, Informative)
The software, as well as the confuguration files, are actually Python. But, you won't notice until your build requirements get quite complex.
Scons keeps track of dependencies using MD5sums on the tail nodes. This takes up a bit more processing time, but more than makes up for it with highly-parallelizable builds (SCons + distcc totally rocks), guaranteed correct builds (never do 'make clean' again!).
We've just converted a project from Make to SCons, and it's cut our build time by about 40%. I might even be able to convince our java guys to try it out, too
Re:Ant does the job... (Score:5, Informative)
If you understood Ant, you would know that it can do this as well.
Re:GUI (Score:4, Informative)
Last time I used it the paths were added as absolute paths so I continued editing my scripts by hand, though.
Re:Ant does the job... (Score:4, Informative)
You don't need to learn make from books because you already know it, and if you knew ant, you wouldn't need to read books like this either.
Even if you didn't know ant, the online documentation is sufficient. That is how I learned ant.
Re:Frankly, I don't care about building Java. (Score:1, Informative)
a good goodbye to make forever (Score:1, Informative)
I'm much more productive using something other than make for building multi-project software packages.
Additional Ant Goodies (Score:4, Informative)
Also, although Ant is used mainly to build Java, it is NOT java-centric. It can be used to compile any language.
Re:Only two words necessary (Score:2, Informative)
Re:Make file (Score:5, Informative)
Just like JCL(IBM's job control lanaguage). Read the New Hackers Dictionary description [outpost9.com] of JCL. An excerpt:
About sums up my opinion of ANT.
Re:Forgive my ignorance... (Score:3, Informative)
Basically Maven is an extra layer on top of Ant. Or another way of putting it is that Maven is way to program Ant in an XML based language called Jelly. Maven has the concept of repositories and versions, so that you can say that a particular jar file requires specific versions of other jar files in the repository. If you find yourself writing a lot of similar Ant code, Maven is definitely worth a look. It takes a little while to get into, but once you do it is fairly straight forward.
Re:I completely agree (Score:1, Informative)
It's a useful thing to do in a mixed j2ee/C++ development environ to provide automated building, unit testing, and documentation for all projects using a uniform set of ant targets (i.e then can run it all remotely with cruisecontrol or similar app)
To run bash shell scripts or do c++ compilation there is an ant extension on sourceforge http://sourceforge.net/projects/ant-contrib/ [sourceforge.net]
Re:SCons (Score:4, Informative)
The 'md5sum' thing ensures that you're not relying on timestamps. Especially important if you're dealing with several machines that might not have their clocks synchronised perfectly. Furthermore, the 'signature' of any of the build nodes is the concatenation of the MD5s of all it's dependencies, PLUS the command lines to generate that node. Change ANY one of those, including changing any compiler flag, and the signature doesn't match, and the node gets rebuilt.
SCons does its own inherent dependency checking, and caches that, too, plus recording the signatures of all the files needed to generate that information. If any of THAT changes, it will re-get dependencies, and then use the result to determine if a node needs to be rebuilt. This, plus the previous part, makes 'make depend' unnecessary. SCons always gets it right, which cannot be said for Make, or (I think) even Ant... (We currently DO have problems with Ant after a 'cvs update'.). I'm pretty sure that you can make your '.depend' files depend on the files that were used to generate it, but the solution [gnu.org] for that for Make (unsure for Ant), is UGLY. SCons handles it all automatically.
SCons also handles cross-platform builds. It's actively tested under *nix and Windows.
Really, if any product deserves to be called a 'category killer' for this category, it isn't Ant, it's SCons.
Re:Kumar? (Score:3, Informative)
Some how I think most /. would better associate with the later meaning of the word.
Re:Forgive my ignorance... (Score:3, Informative)
Confusing? Well it's not something you should rush into. IF you would like more information about Maven, take a look at Maven: A Developer's Notebook [amazon.com], Vincent Massol and I just finished this bok in March of this year and it was released last month. It is a good introduction to Maven.
And, if you were wondering, the developers are doing a better job at project documentation for Maven 2.0. It is shaping up well.
Re:Ant is simply not a Make replacement (Score:3, Informative)
But still, ant is no make. It's not ant's fault, but more a fault of the underlying reason that make is both powerful and problematic. Make leverages the power of it's shell and all the utilities that have been written explicitly to make shell scripting possible. Make (by itself) doesn't do a lot except call a bunch of programs using a reverse-chaining algorthim. It's the value of all those shell programs that give make it's lifting power.
Ant can call a platform's shell programs too, but then you run into difficulties in communicating rich information between the programs, and ant becomes just a funny, XML configured, JAVA version of make. That's why ant's logging capabilites far outstrip those of make, because it's logging facility can differentiate between errors, warnings, and informational messages, routing them to text files, xml files, databases, and web pages.