Product 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
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.
From the Publisher
About the Author
Steve Holzner is an award-winning author who has been writing about Java topics since Java first appeared. He's a former PC Magazine contributing editor, and his many books have been translated into 18 languages around the world. His books sold more than 1.5 million copies, and many of his bestsellers have been on Java. Steve graduated from MIT and got his PhD at Cornell; he's been a very popular member of the faculty at both MIT and Cornell, teaching thousands of students over the years and earning an average student evaluation over 4.9 out of 5.0. He also runs his own software company and teaches week-long classes to corporate programmers on Java around the country.
Excerpted from Ant The Definitive Guide by Steve Holzner. Copyright © 2005. Reprinted by permission. All rights reserved.
Up to this point, youve been working solo with Ant, but - as with any major build Tool - Ant can be used in team environments. Theres a lot of support built in for the
Concurrent Version System (CVS) in Ant, and this chapter is all about making code sharing in teams with CVS happen.
Source Control and Ant
When you work in teams, you have to coordinate your efforts. That means discussing and planning, but even with the best of intentions, you can still end up with unintentional conflicts. You may have made some brilliant changes to the code, only to find them wiped out by mistake when another programmer uploads his own version of the same file.
Source control helps prevent these problems by controlling access to code and by maintaining a history of the changes made so things arent destroyed unintentionally. Storing a history of your code is powerful; you can compare a new (buggy) file against an older one, and you can revert to a previous version in case things have gone bad.
Ant has several source control tasks, shown in Table 6-1.
Though Ant lets you work with various source control systems, most of its support revolves around CVS, which is used throughout this chapter. CVS is an open source project that started as a set of Unix shell scripts in 1986 and came into its own with dedicated software in 1989. Support for CVS is available on many operating systems: Unix, Linux, Windows, Mac, and others. For the full CVS story, look at cvshome.org.
To work with CVS using Ant, you need access to a CVS server. Most Linux and Unix installations come with a built-in CVS server. To test if you have a working CVS installation, type cvs --help at the prompt; you should see a list of help items. If you cant find a CVS server, you can download what you need from cvshome.org. Many CVS servers are available for Windows, such as CVSNT, available for free from cvsnt.org. To install CVSNT, download the executable file and run it.
The idea behind CVS, as with any repository software, is to manage and record changes to source code. What corresponds to a project for Ant is a module in CVS. Modules are represented by directories in CVS; the files you share are stored in the CVS repository. When you retrieve a file from the repository, you check the file out. After youve modified the file, you commit the file, checking it back in and sending those changes to the repository. If you want to refresh your own copy of a file, you update it from the repository.
Because each file must be independently tracked, CVS gives the individual files a version number automatically. Each time a file is committed, its version number isincremented. When you commit files to the repository, theyll get a new version number as well.
Using the cvs task, you communicate with the CVS server using CVS commands, which appear in Table 6-2.
Read more about these commands in the CVS guide at cvshome.org/docs/manual/cvs-1.11.7/cvs_16.html.
The first step in working with CVS is to log into the CVS server, typically done with the cvspass task.
Logging In
You use the cvspass task to log into a CVS server to get access to the code stored in the CVS repository. This task adds entries to a .cvspass file, which has the same affect as a CVS login command. When a .cvspass file has been created, subsequent logins will get the needed data from this file, and you wont have to supply a password again.
The values you assign to the attribute named cvsroot use the same format of strings that appear in a CVS .cvspass file, which specifies the protocol type, username, server, and repository location. For example, using the pserver protocol with a user named Steven, a server named STEVE, and a repository location of /home/steven/repository, cvspass would look like:
.
.
.
The CVS-related tasks can read the CVS root value from the cvsroot attribute, if they support that attribute, or from the CVSROOT environment variable.
In Windows, when your username includes a space or spaces, you might run into problems with the cvsroot attribute. In that case, assign a value to the CVSROOT environment variable instead (e.g., C:\ant\ch06>set CVSROOT=:pserver:Steven Holzner@STEVE:/home/steven/repository) and then use cvspass or other CVS-related tasks in your build file normally.
Working with the Server
The cvs task lets you interact with the CVS server after youve logged in. The attributes of this task appear in Table 6-4; to use this task, the cvs command must work on the command line (i.e., the cvs binary must be in your path).
This task is designed to pass commands on to CVS verbatim. For example, heres how youd pass a CVS diff command to the CVS server:
You can nest commandline elements and use the value attribute of argument elements to pass arguments to the CVS server; you can pass the diff command this way:
or this way, using the argument elements line attribute:
/