Table of Contents
The details of the Ant template are provided below. If you'd like to just dive in and give it a whirl without reading the details below, here's a quick-start guide:
build.properties, and make any changes to the defaults
in the local-build.properties. Typically, you'll only need to set
the lib.dir, and possibly the java.src.dir, config.dir and web.dir properties.build.xml file and make any needed adjustments to the
entities at the beginning of the file. These are set to reasonable
defaults, but you may need to add some project-specific libraries
to the java.compile.classpath path, add source files to the project.client.src.files patternset, etc.create-wars target to point to include the necessary
libraries and web files in the archive, and to pull the correct web
deployment descriptor. You may also need to adjust the create-ejbjars target for similar reasons. These two targets may also need to be
adjusted if your project needs more than one web or EJB archive.as-configs, you just set as.type to the appropriate value.
Look through the application server configuration file and add any
necessary property settings to your local-build.properties. Do the
same for your web service engine, if your project involves web services.deploy-app target and see what breaks. The Ant template applies the general principles laid out in Ch. 17, with some additional extensions added for the purposes of the book examples. This template is the basis of the build scripts for the book examples, but it is designed to be a generic template that can be used to create your own build scripts for development projects.
The Java Enterprise in a Nutshell (JENT) Ant Template provides the following features:
build.xml),
with a collection of targets that you can customize to suit your
project. These targets cover:
build.properties),
all "local" properties for a given environment (developer's
workstation, etc.) are kept in a properties override file (local-build.properties). The template consists of the following files:
build.xml)build.properties) local-build.properties)as-configs directory)wse-configs directory)These files work together in the build template as shown in Figure 1.

Figure 1: Ant Template Structure
The build.xml file loads your local-build.properties file first, then loads the global build.properties file. This allows
you to override any properties found in the build.properties file,
the application server configuration file, and/or the web service
engine configuration file, as needed, to suit your environment.
Once the properties for the build script have been set up, the configuration and target definitions suitable for the application server and web service engine are loaded. The target definitions from these configuration files are invoked in the build script to accomplish key tasks, such as deploying applications or creating a component archive.
The build script template, build.xml,
includes default definitions for the following targets. All of these
targets can be invoked directly by the developer.
During typical
development, you'll just need to invoke the deploy-app target.
Through its dependencies on other targets, invoking this target
will compile the application code, assemble your component archives,
assemble an application archive and attempt to deploy it. If you're
using local and/or server-side unit tests in your development (as
you should!), you can use the run-tests target. This will compile
all your application code and tests, run the local tests, deploy
the test-enabled version of the application, and run any server-side
tests.
Each of these targets may also use one or more
internal support targets, as described below. These support targets
my reside in the template build.xml directly,
or may be imported from either the application server configuration
or the web service engine configuration. The default implementations
of these targets are designed to be as generic as possible, so
that in most cases you can configure the script for a particular
project by simply setting the values of the various properties
defined immediately after these target descriptions. But in some
cases, depending on the needs of the project, these default target
definitions may need to be adjusted as well.
clean java.classes.dir and java.test.classes.dir directories,
deletes any jar, war or ear files found in the project base
directory, deletes any TEST-*.xml files generated
by the test targets, deletes the
generated.dir directory, and finally invokes the as-clean target
from the application server configuration, to clean up any
application server-specific artifacts generated by its targets.
compilejava.src.dir property, using the value
of the project.src.files patternset
as the filter to select the files in this directory to be compiled.
The compiled classes are written to the java.classes.dir directory.
compile-clientsjava.src.dir property,
using the value of the project.client.src.files patternset
as the filter to select the files in this directory to be compiled.
The compiled classes are written to the java.classes.dir directory.
compile-tests java.test.src.dir property,
using the project.test.src.files patternset as
the filter to select the files in this directory to be compiled.
The compiled classes are written to the java.test.classes.dir directory. compile target, since
it's assumed that the unit tests invoke the application code,
and therefore need to be compiled against the project classes.
create-app create-wars and create-ejbjars support targets are used to assemble any component archives
that are part of the application. create-wars support target,
in turn, uses the as-create-war target imported from the application
server configuration to assemble war files. It may also use
the wse-prepare-service and wse-process-war targets imported
from the web service engine configuration, if the web archive
includes web service implementations. create-ejbjars support target uses the as-create-ejb-jar, wse-prepare-service and wse-process-ejb-jar targets.create-app target
uses the as-create-ear target from the application
server configuration to assemble the application archive for
the project. create-wars and create-ejbjars targets.
create-test-app create-app target, but it generates
a test-enabled version of the application. It invokes the create-test-wars support target to generate test-enabled web archive(s) (useful
if Cactus is being used to run server-side unit tests), and
the create-ejbjars support target to generate any EJB archives.
It then uses the as-create-ear support target from the application
server configuration to assemble the test-enabled application
archive.create-test-wars and create-ejbjars targets.
deploy-app as-deploy support target imported from the application server configuration. create-app target.
deploy-test-app as-deploy support
target imported from the application server configuration. create-test-app and run-local-tests targets.
env generate-artifacts gen-web-artifacts, gen-ejb-artifacts, gen-ws-client-stubs)
that you may find useful for generating XDoclet and/or web
service artifacts.
run-tests run-local-tests and run-server-tests targets
described below.compile-tests target.
run-local-tests junit task to run the tests from
the java.test.classes.dir directory,
using the project.local.test.classes patternset
as the filter to select the test classes to be executed. The
local-tests-failed property is set if any of the tests fail.compile-tests target.
run-server-tests cactus.* properties in the build.properties/local-build.properties.
Any tests found in the java.test.classes.dir directory that
match the project.server.test.classes patternset are run by
this target. If any of the tests fail, the server-tests-failed property is set. deploy-test-app target, to ensure
that the test-enabled application is deployed first.
verify-app as-verify-module support target
from the application server configuration, passing it the application
archive generated from create-app as the module to be verified.create-app target.
The following properties and Ant entities are used by the targets above
(and their support targets). The text properties can be overridden
from their defaults in your local-build.properties. The Ant entities
(patternsets, classpaths, etc.) can be altered directly in the build.xml file.
as.typeas.config.fileconfig.dirgenerated.dirjava.classes.dirjava.debugjava.src.dirjava.test.src.dirjava.test.classes.dirjava.compile.classpath java.test.compile.classpath build.xml that defines
the classpath used to compile test source code. lib.dir build.properties demonstrates
the intended use of this property. Various support libraries
are referenced starting from the lib.dir directory. This allows
a developer to place all their third-party libraries into one
central place on their workstation, and simply override the lib.dir property in their local-build.properties to point the build script
to their libraries. If necessary, the individual library properties
(e.g., log4j.jar, jstl.jar) can be overridden individually, if
the build environment has particular libraries stored in separate
libraries for some reason. project.src.files build.xml that
specifies what source files in the java.src.dir are
part of the deployed application, rather than client files.project.test.src.files build.xml that
specifies what source files in the java.test.src.dir directory
are to be considered test classes. project.local.test.classesbuild.xml that
specifies the classes in the java.test.classes.dir that are local
unit test classes, rather than server-side unit tests. project.server.test.classesbuild.xml that
specifies the classes in the java.test.classes.dir that are server-side
unit test classes. web.dirwse.config.filewse.typewse-configs directory. Setting this
property to
"xxx" causes "wse-configs/wse-xxx-configs.xml" to
be imported into the build script. If you want to load a web
service configuration file from a different location, or using
a different file naming convention, then set the value of the
wse.config.file property directly. Application Server Configurations
Once you've installed an application server, you
then need to configure the build script to use it. First, you need
to ensure that the appropriate application server configuration file
is imported into the main build script. If your application server
config file sits in the as-configs directory and is named using the
"as-XXX-config.xml" convention, then you can simply override the
value of the as.type property in your local-build.properties file.
For example, if you place this in your local-build.properties:
as.type = jboss
Then the as-configs/as-jboss-config.xml configuration
file will be imported into the build script. If your application
server config file doesn't sit in the as-configs directory, and/or
doesn't follow the file naming convention, then you can also directly
override the value of the server.config.file property in your local-build.properties file. This property is set to as-configs/as-${as.type}-config.xml in the build.properties, but you can override it to point directly
to any file you choose, e.g.:
server.config.file = stage-configs/stage-jboss-config.xml
All application
server configurations use the following standard properties, which
usually have reasonable defaults set for them, but may need to be
overridden in your local-build.properties file,
depending on how your server is set up. You can safely use these
properties in your build script as needed.
as.http.hostnameas.http.portas.j2ee.core.classpathbuild.xml as an element
of the compilation process. Each application server configuration file may
also have its own set of properties that you need to override
in your local-build.properties file. The JBoss config
file, for example, uses a property named jboss.home to
indicate the root directory of the JBoss installation. You would
need to set this property in your
local-build.properties to point to your local JBoss
directory:
jboss.home = /opt/jboss-4.0.3
Review the application server configuration file to see what server-specific properties it requires you to set.
Every application server configuration file must
provide definitions for the following targets. The build script uses
these targets to accomplish key tasks, such as deploying an application.
These targets are implemented to suit the application server, and
insulate the build script from server-specific details. Note that
these targets are NOT meant to be invoked directly, they are only
used by the build script within its targets. The only exceptions
are the as-server-start and as-server-stop targets, which are can
be used directly by the developer to start/stop the configured application
server.
Each target has a set of required and optional
properties that it expects the caller to provide. Consult the application
server configuration file for details on these properties. You can
see the properties in use in the template build.xml file
where it invokes these application server targets.
as-cleanas-create-earas-create-ejb-jaras-create-waras-deployas-server-startas-server-stopas-verifyWeb Service Engine Configurations
If your project includes web services, you must
also configure the web service engine you plan to use. This process
mirrors the process for setting up the application server -
you need to either override the wse.type property, which will load
a configuration from wse-configs/wse-<wse.type>-config.xml, or you
can set the wse.config.file property to directly choose the configuration
file from any arbitrary location. For example, if you wanted to use
the Apache Axis configuration included with the template, then you
could just set the wse.type property in your local-build.properties like so:
wse.type = axis
This will cause the file wse-configs/wse-axis-config.xml to be imported into the build script. If you
All web service engine configurations use the following
standard properties, which usually have reasonable defaults set for
them, but may need to be overridden in your local-build.properties file,
depending on how your engine is set up. You can safely use these
properties in your build script as needed.
wse.client.compile.librarieswse.client.run.librarieswse.service.compile.librarieswse.service.run.librariesEach web service engine configuration file may
also have its own set of properties that you need to override in
your local-build.properties file. The Apache Axis config
file, for example, uses a property named axis.home to
indicate the root directory of the Axis installation. You would
need to set this property in your local-build.properties to
point to your Axis installation directory:
axis.home = ${lib.dir}/axis-1.3
Review the web service engine configuration file to see what engine-specific properties it requires you to set.
Every web service engine configuration file must provide definitions for the following targets. The build script uses these targets to accomplish key tasks, such as preparing component archives prior to deplyoment. These targets are implemented to suit the web service engine, and insulate the build script from engine-specific details. Note that these targets are NOT meant to be called directly, they are only used by the build script within its targets.
Each target has a set of required and optional
properties that it expects the caller to provide. Consult the web
service engine configuration file for details on these properties.
You can see the properties in use in the template build.xml file
where it invokes these web service engine targets.
wse-generate-client-stubswse-post-deploywse-prepare-servicewse-process-earwse-process-ejb-jarwse-process-war