About this Book

This book is about Ant, the award-winning Java build tool. Ant has become the centerpiece of so many projects’ build processes because it’s easy to use, is platform-independent, and addresses the needs of today’s projects to automate testing and deployment. From its beginnings as a helper application to compile Tomcat, Apache’s Java web server, it has grown to be a stand-alone tool adopted across the Java community, and in doing so has changed people’s expectations of their development tools.

If you have never before used Ant, this book will introduce you to it, taking you systematically through the core stages of most Java projects: compilation, testing, execution, packaging, and delivery. If you’re an experienced Ant user, we’ll show you how to “push the envelope” in using Ant. We place an emphasis on how to use Ant as part of a large project, drawing out best practices from our own experiences.

Whatever your experience with Ant, we believe that you will learn a lot from this book and that your software projects will benefit from using Ant as the way to build, test, and release your application.

Who Should Read this Book

This book is for Java developers working on software projects ranging from the simple personal project to the enterprise-wide team effort. We assume no prior experience of Ant, although even experienced Ant users should find much to interest them in the later chapters. We do expect our readers to have basic knowledge of Java, although the novice Java developer will benefit from learning Ant in conjunction with Java. Some of the more advanced Ant projects, such as building Enterprise Java applications and web services, are going to be of interest primarily to the people working in those areas. We’ll introduce these technology areas, but we’ll defer to other books to cover them fully.

How this Book is Organized

We divided this book into three parts. Part 1 introduces the fundamentals of Ant and shows how to use it to build, test, package, and deliver a Java library. Part 2 takes the lessons of Part 1 further, exploring how to use Ant to solve specific problems, including coordinating a multi-project build, and deploying and testing web and Enterprise applications. Part 3 is a short but detailed guide on how to extend Ant in scripting languages and Java code, enabling power users to adapt Ant to their specific needs, or even embed it in their own programs.

Part 1

In chapter 1, we first provide a gentle introduction to what Ant is, what it is not, and what makes Ant the best build tool for building Java projects.

Chapter 2 digs into Ant’s syntax and mechanics, starting with a simple project to compile a single Java file and evolving it into an Ant build process, which compiles, packages, and executes a Java application.

To go further with Ant beyond the basic project shown in chapter 2, Ant’s abstraction mechanisms need defining. Chapter 3 introduces Ant’s properties and datatypes, which let build-file writers share data across parts of the build. This is a key chapter for understanding what makes Ant shine.

Ant and test-centric development go hand in hand, so chapter 4 introduces our showcase application alongside JUnit, the tool that tests the application itself. From this chapter onwards, expect to see testing a recurrent theme of the book.

After packaging the Java code in chapter 5, we look in chapter 6 at launching Java and native programs. Chapter 7 takes what we’ve packaged and distributes it by email and FTP and SCP uploads.

It’s often difficult to envision the full picture when looking at fragments of code in a book. In chapter 8, we show a single build file that merges all the stages of the previous chapters. Chapter 8 also discusses the issues involved in migrating to Ant and adopting a sensible directory structure, along with other general topics related to managing a project with Ant.

Part 2

The second part of the book extends the core build process in different ways, solving problems that different projects may encounter. Chapter 9 starts by showing how to extend Ant with optional and third-party tasks to perform new activities, such as checking out files from revision control, auditing code, and adding iteration and error-handling to a build file.

Chapter 10 looks at big-project Ant—how to build a big project from multiple subsidiary projects. This chapter is complemented by Chapter 11, which uses the Ivy libraries to address the problem of library management. Having a tool to manage your library dependencies and to glue together the output of different projects keeps Java projects under control, especially large ones.

Web development is where many Java developers spend their time these days. Chapter 12 shows how to package, deploy, and then test a web application. You can test a web application only after deploying it, so the development process gets a bit convoluted.

Chapter 13 discusses a topic that touches almost all Java developers: XML. Whether you’re using XML simply for deployment descriptors or for transforming documentation files into presentation format during a build process, this chapter covers it.

Chapter 14 is for developers working with Enterprise Java; it looks at how to make an application persistent, how to deploy it on the JBoss application server, and how to test it with Apache Cactus.

The final two chapters of Part 2 look at how to improve your development processes. Chapter 15 introduces continuous integration, the concept of having a server automatically building and testing an application whenever code is checked in. Chapter 16 automates deployment. This is a topic that many developers neglect for one reason or another, but it typically ends up coming back to haunt us. Automating this—which is possible—finishes the transformation of how a Java project is built, tested, and deployed.

Part 3

The final part of our book is about extending Ant beyond its built-in capabilities. Ant is designed to be extensible in a number of ways. Chapter 17 provides all the information needed to write sophisticated custom Ant tasks, with many examples.

Beyond custom tasks, Ant is extensible by scripting languages, and it supports many other extension points, including Resources, Conditions, FilterReaders, and Selectors. Monitoring or logging the build process is easy to customize, too, and all of these techniques are covered in detail in chapter 18.

At the back

Last but not least are three appendices. Appendix A is for new Ant users; it explains how to install Ant and covers common installation problems and solutions. Because Ant uses XML files to describe build processes, appendix B is an introduction to XML for those unfamiliar with it. All modern Java integrated development environments (IDEs) now tie in to Ant. Using an Ant-enabled IDE allows you to have the best of both worlds. Appendix C details the integration available in several of the popular IDEs.

What we do not have in this edition is a quick reference to the Ant tasks. When you install Ant, you get an up-to-date copy of the documentation, which includes a reference of all Ant’s tasks and types. Bookmark this documentation in your browser, as it is invaluable.

Online Resources

There’s a web site that accompanies this book: http://antbook.org/. It can also be reached from the publisher’s web site, www.manning.com/loughran. You’ll find links to the source and the author forum plus some extra content that isn’t in the book, including a couple of chapters from the previous edition and a bibliography with links. Expect more coverage of Ant-related topics as time progresses.

This antbook.org web site links to all the source code and Ant build files in the book, which are released under the Apache license. They are hosted on the SourceForge open source repository at http://sourceforge.net/projects/antbook.

The other key web site for Ant users is Ant’s own home page at http://ant.apache.org/. Ant and its online documentation can be found here, while the Ant user and developer mailing lists will let you meet other users and ask for help.

Code Conventions

Courier typeface is used to denote Java code and Ant build files. Bold Courier typeface is used in some code listings to highlight important or changed sections.

Code annotations accompany many segments of code. Certain annotations are marked with numbered bullets. These annotations have further explanations that follow the code.

Author Online

Purchase of Ant in Action includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the authors and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/loughran. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialog between individual readers and between readers and the authors can take place. It is not a commitment to any specific amount of participation on the part of the authors, whose contribution to the AO remains voluntary (and unpaid). We suggest you try asking the authors some challenging questions, lest their interest stray!

The Author Online forum and the archives of previous discussions will be accessible from the publisher’s web site as long as the book is in print.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset