Chapter 5: Building Java Applications with Ant


Overview

This chapter explains the techniques involved in using Ant to build and deploy Java applications in an orchestrated fashion. Once you understand these fundamental techniques, you will be ready for the complexities of Chapter 6, Building J2EE Applications with Ant, in which we build a Model 2 application complete with EJBs, servlets, and JSPs.

During the course of this chapter, we will build a Hello World example. Because the emphasis is on how to build components with Ant ”and not the mechanics of implementing these various components ”the example is meant to be as simple as possible. We will package the application and the common JAR, construct a buildfile that creates an applet, and construct a master buildfile that coordinates the entire build.

The source code for the Hello World example is divided into several directories. Each directory has its own Ant buildfile, which contains instructions to compile the components and package the binaries. Each directory also includes the requisite configuration files (such as manifest files). The master Ant buildfile, located in the root directory, calls the other buildfiles and coordinates the entire build.

This divide-and-conquer technique for organizing components into separate directories is quite common with Ant. It may seem like overkill on a simple project like this one, but consider building a system with 50 components. Each component has its own set of deployment descriptors and configuration files, and each component is deployed in different containers. The divide-and- conquer technique becomes necessary to mange the complexity ”it also makes it easier to reuse components.

Following is the directory structure for the Hello World project. We will use this same structure for the more complex example in Chapter 6:

 Model 2 Hello World root +---Model +---Application +---Applet +---WebApplication +---EJBeans 

The Model directory holds the common code (in this simple project, only the application will access the common code). The Application directory holds the Java application code, including the manifest file that marks the deployment JAR as executable. The Applet directory holds the applet code. The WebApplication and EJBeans directories are discussed in Chapter 6.




Professional Java Tools for Extreme Programming
Professional Java Tools for Extreme Programming: Ant, XDoclet, JUnit, Cactus, and Maven (Programmer to Programmer)
ISBN: 0764556177
EAN: 2147483647
Year: 2003
Pages: 228

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net