JaVa
   

Building Java apps with Ant

Overview

This chapter explains the techniques involved in using Ant to build and deploy Java apps in an orchestrated fashion. Once you understand these fundamental techniques, you will be ready for the complexities of , “Building J2EE apps with Ant,” in which we build a Model 2 app 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 app 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 :

Model 2 Hello World root
+---Model
+---app
+---Applet
+---Webapp
+---EJBeans


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


JaVa
   
Comments