ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mahlen Morris" <>
Subject An Example of Hierarchical build.xml's in Ant 1.1.
Date Thu, 19 Oct 2000 00:12:18 GMT
OK, here's a brief description of the multi-tiered Ant build system I
created for my team. Some details have been obsfucated, since my
company is still in stealth mode. I'll be more clear than probably
needed for most of you, just because of the possible wide disparity in

Our source code is in Perforce (hereafter refered to as P4), which,
like almost every other source code control system, creates and
maintains a copy of the source tree on my hard drive, which is where I
edit files. In my case, this tree is located at C:\src\src, but other
developers have put it into different places. The runtime environment
is Weblogic, which is also running on my machine, and that is where i
want the compiled and EJB jar'd results of a build to go. There is
also a staging directory (i use the symbol 'dest'), where .class files
are built before being held.

So, in \src\src, there is this build.xml:

<project name="Mahlen's Really Exciting Product" default="build"
  <target name="init" >
    <property file="" />
    <property file="" />

  <target name="build" depends="init, mkdir, apple, banana, cherry"/>
  <target name="clean" depends="init, doclean" />

  <target name="doclean" depends="init">
    <deltree dir="${dest}" />

  <target name="mkdir" depends="init" >
<!-- Not really needed, since Ant will make the directories it needs,
but clearer. -->
    <mkdir dir="${dest}"/>
    <mkdir dir="${ejbdest}"/>
    <mkdir dir="${meta-inf}"/>
    <mkdir dir="${nightly}"/>
  <target name="apple"> <!-- a package in our source tree -->
    <ant dir="com/mahlen/apple"/>


<!-- For deploying into the Weblogic installation. -->
  <target name="deploy" depends="init" >
    <ant dir="com/mahlen/apple" target="deploy" />
    <ant dir="com/mahlen/banana" target="deploy" />
    <ant dir="com/mahlen/cherry" target="deploy" />


If it's not obvious, first the init target is run, to pick up all of
the properties, and then the various sub-builds are called to do the
actual work that each one requires.

You'll notice that the two property files, and are read first thing.
is checked into P4, and it contains the (duh) default values for the
P4 source directory, the staging area, and the Weblogic directory,
among other things. However, the local or per machine values can be
set in the file, which is not in P4.

OK, so in, say, com/mahlen/apple, there is a build.xml like this:

<project name="Apple Part" default="build" basedir=".">
  <target name="init" unless="TSTAMP" >
    <property file="../../../" />
    <property file="../../../" />

  <target name="build" depends="init" >
    <javac srcdir="." destdir="${dest}" includes="*.java"

  <target name="deploy" depends="init" >
    <copydir src="${dest}\com\mahlen\apple"
dest="${weblogic_root}\myserver\serverclasses\com\mahlen\apple" />

The 'init' target uses TSTAMP as an indicator that the property files
have already been read. So if the root build.xml is being called, then
the property files won't be read again (which would be harmless, I
suppose, but would waste time). So, in the apple directory, you can
type 'ant build' and you'd rebuild just the apple part. 'ant deploy'
would copy just that section to weblogic, and you can combine them, of
course. Of course, if there are dependancies between packages that are
affected by your code changes, this won't quite work, but this is a
system for self-aware programmers, not for, say, my cats.

Anyhow, not rocket science, but that's how it works, and people seem
pretty happy with it. Any comments/questions/flames, send 'em on in.


Any reviewer who expresses rage and loathing for a novel is
preposterous.  He
or she is like a person who has put on full armor and attacked a hot
        --Kurt Vonnegut, Jr.

View raw message