Chapter 3: Ant

Ant is becoming increasingly widely used as a build and deploy tool for Java applications. This chapter is about how I am using Ant in this tutorial. It is nothing particular to do with Jini. This chapter can be skipped until you start building and deploying examples from this book.

3.1. Introduction

Applications consisting of multiple source benefit from having some build tool to automate compilation, deployment, testing, etc. 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 has cross-platform support and ant build files can be written in an O/S independant way.

This tutorial is being adapted to use ant instead of make and Unix shell scripts. This chapter is about 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, skip past this chapter. Individual build files for each project will be given in the relevant chapters.

3.2. Toplevel build file

There are two general parameters that need to be set for your own environment

  1. jini.home - the pathname to where Jini has been unpacked. This is used to define the jini.jars variable which contains the standard Jini class files

  2. localhost - the IP address or hostname of the current machine. In my testing, I run basic tests from this machine

These are defined in the build.xml in the tutorial's root directory.

Similar to many projects, we adopt the following directory structure

  1. src - the directory for all source files

  2. build - where all class files are built

  3. dist - where distribution files such as jar files are created

  4. resources - where things like policy files and configuration files are kept

  5. httpd.classes - this is non-standard, but is where we need to copy files so that an HTTP server can find them

These are all defined in the build.xml file in the tutorial's root directory.

The following targets are defined

  1. compile - compile all source files

  2. dist - build the distribution, typically jar files

  3. build - compile and distribute (redundant)

  4. deploy - copy files to their destination, typically some jar files to an HTTP server

  5. clean - remove all class files, jar files and source backups

  6. run -DrunFile=... - run a project

  7. usage - print a list of options

The toplevel 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; 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


3.3. Project files

Each project is defined in an Ant file in the antBuildFiles directory. The purpose is to implement the toplevel build targets for each project. Each of these project files inherits values from the toplevel file, namely

  1. jini.home

  2. jini.jars

  3. src

  4. dist

  5. build

  6. httpd.classes

Each project uses only a small number of the files from the src directory. These are defined in the src.files variable. For example, for the complete.FileClassifierServer project discussed in the chapter "A Simple Example" the source files are defined by

<property name="src.files"

Since Jini is a distributed system, not all class files are required by all components. Typically a server will require some files whereas a client will require others. These are defined by two further variables

<!-- Class files to run the server -->
<property name="class.files"

<!-- Class files for the client to download --->
<property name="class.files.dl"

The rest of each project file is fairly straightforward. The compile target compiles all files in the src.files list; the dist target builds jar files: usually two of them, one for the server and one for the client; the deploy target copies the jar files for the client to an HTTP server; the run target starts a JVM with appropriate parameters. Note that the JVM must be started as a separate VM as it sets a security policy (discussed later) which cannot be done within an already running Ant JVM.

The complete project file for complete.FileClassifierServer is in the file complete.FileClassifierServer.xml:


3.4. Copyright

If you found this chapter of value, the full book "Foundations of Jini 2 Programming" is available from APress or Amazon .

This file is Copyright (©) 1999, 2000, 2001, 2003, 2004, 2005 by Jan Newmarch (

Creative Commons License This work is licensed under a Creative Commons License, the replacement for the earlier Open Content License.