Table of Contents
Abstract
Ant is becoming increasingly widely used as a build and deploy tool for Java applications. This chapter covers how I am using Ant in this tutorial. It has nothing in particular to do with Jini. Feel free to skip this chapter until you start building and deploying the examples from this book.
Applications consisting of multiple source files benefit from having a build tool to automate compilation, deployment, testing, and so on. Many of these tools are operating system-specific, such as make (although Windows versions now exist). Ant has become an increasingly popular tool for Java applications since it offers cross-platform support and Ant build files can be written in an operating system-independent way.
This book is adapted to use ant instead of make and Unix shell scripts. This chapter covers the use of ant for this tutorial; it is not about Jini at all, so unless you want to see how the applications are currently built, I recommend that you skip this chapter. Individual build files for each project will be given in the relevant chapters.
Two general parameters need to be set for your own environment:
jini.home: The pathname to the location where Jini has been unpacked. This parameter is used to define the jini.jars variable that contains the standard Jini class files.
localhost: The IP address or hostname of the current machine. In my testing, I run basic tests from this machine.
These parameters are defined in build.xml in the tutorial's root directory.
Similar to many projects, you adopt the following directory structure:
src: The directory for all source files.
build: The location where all class files are built.
dist: The location where distribution files such as .jar files are created.
resources: The location where things like policy files and configuration files are kept.
httpd.classes: This is nonstandard, but it is the location where we need to copy files so that an HTTP server can find them.
These directories are all defined in the build.xml file in the tutorial's root directory.
The following targets are defined:
compile: Compile all source files.
dist: Build the distribution, typically .jar files.
build: Compile and distribute (redundant).
deploy: Copy files to their destination, typically some .jar files to an HTTP server.
clean: Remove all class files, .jar files and source backups.
run -DrunFile=...: Run a project.
usage: Print a list of options.
The top-level file build.xml defines these targets. The main function of each target is to run the target again in each of the projects. So compile runs compile in each project and deploy runs deploy in each project, whereas run calls run only in the selected project. The projects are each defined in an Ant file in the antBuildFiles directory. The build.xml file is