Here is a simple Ant build file which, if placed in the root directory of
your project (root directory being the directory that contains your src and
classes directories), will compile all classes under <root dir>/src into
<root dir>/classes, computing dependencies beforehand. It has these
targets:
init - preps the build directories
dependencies - computes dependency relationships
classes - compiles all classes
clean - removes all compiled classes
usage - displays a help screen (this is the default target)
all - runs init, dependencies, and classes
It relies on the placement of 3rd-party jar or zip files in <root dir>/lib.
Nevertheless, this directory as well as the source and build directories,
compile options, etc. can be controlled through command-line options.
To use it in JDE, do this:
1. Download and install Ant according to the instructions (essentially, you
just set a few environment variables)
2. Start Emacs
3. In JDE, set jde-make-program to ant
4. In JDE, set jde-make-args to -emacs -find build.xml
5. In JDE, set jde-read-make-args to t
6. Choose JDE-->Build from the menu bar
7. In the minibuffer, supply the target 'all'
Here's the build.xml file:
==============================
<?xml version="1.0"?>
<!-- ============================================================= -->
<!-- Ant buildfile for building Java projects -->
<!-- ============================================================= -->
<project name="build" default="usage">
<!-- =========================================================== -->
<!-- Set project properties. -->
<!-- These can be overridden from the command line using -D -->
<!-- =========================================================== -->
<property name="src.dir" value="src"/>
<property name="build.dir" value="classes"/>
<property name="lib.dir" value="lib"/>
<property name="classes.includes" value="**/*.java"/>
<property name="clean.includes" value="**/*"/>
<property name="classes.debug" value="on"/>
<property name="classes.optimize" value="off"/>
<property name="classes.deprecation" value="off"/>
<property name="classes.target-vm" value="1.2"/>
<property name="fail.on.error" value="false"/>
<property name="classes.depend" value="false"/>
<!-- =========================================================== -->
<!-- Init target. -->
<!-- Creates build and deploy directories, if it is needed. -->
<!-- =========================================================== -->
<target name="init"
description="creates directory structure if needed">
<tstamp/>
<mkdir dir="${build.dir}"/>
</target>
<!-- =========================================================== -->
<!-- Dependencies target. Recursively scans the build directory -->
<!-- deletes any class files that are out of date because files -->
<!-- which they depend have changed, for safer incremental build -->
<!-- =========================================================== -->
<target name="dependencies"
depends="init"
description="analyzes dependencies">
<echo message="Removing any outdated dependent class files"/>
<depend cache="deps"
closure="yes"
srcdir="${src.dir}"
destdir="${build.dir}"/>
</target>
<!-- =========================================================== -->
<!-- Usage target. Simply prints a help message -->
<!-- =========================================================== -->
<target name="usage"
description="prints a help message">
<echo message="Build File for Java project"/>
<echo message=" ant [options] [[-Dproperty=value]] [target]"/>
<echo message=""/>
<echo message="Options: "/>
<echo message=" Use -help option to see usage for Ant itself"/>
<echo message=" Use -projecthelp option to a list of targets"/>
<echo message=""/>
<echo message="Properties: "/>
<echo message=" basedir=base dir, Default=${basedir}"/>
<echo message=" src.dir=source dir, Default=src"/>
<echo message=" build.dir=build dir, Default=build"/>
<echo message=" classes.includes=, default=**/*.java"/>
<echo message=" clean.includes, default=**/*"/>
<echo message=" classes.debug=(on|off), Default=on"/>
<echo message=" classes.optimize=(on|off), Default=off"/>
<echo message=" classes.deprecation=(on|off), Default=off"/>
<echo message=" classes.target-vm=(1.1|1.2|1.3), Default=1.3"/>
<echo message=" classes.depend=(true|false), Default=false"/>
<echo message=" build.compiler=(modern|classic|jikes|jvc),
Default=classic"/>
<echo message=" fail.on.error=(true|false), Default=false"/>
</target>
<!-- =========================================================== -->
<!-- All target. Simple 'entry-point' target that hits all the -->
<!-- relevant targets. This target should be the one run most -->
<!-- by developers. -->
<!-- =========================================================== -->
<target name="all"
depends="init,classes"
description="runs: [init,classes]">
<echo message="Building all components"/>
</target>
<!-- =========================================================== -->
<!-- Path definitions. Note that these are NOT TARGETS. They -->
<!-- build a set of path definitions which can then be -->
<!-- referenced in targets such as javac and ejbjar. -->
<!-- =========================================================== -->
<path id="lib.class.path">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
<include name="**/*.zip"/>
</fileset>
</path>
<path id="build.class.path">
<pathelement path="${build.dir}"/>
<path refid="lib.class.path"/>
</path>
<!-- =========================================================== -->
<!-- Classes target. Recompiles any out-of-date java files. -->
<!-- =========================================================== -->
<target name="classes"
depends="init,dependencies"
description="compiles Java files">
<echo message="Compiling class files"/>
<javac srcdir="${src.dir}"
destdir="${build.dir}"
debug="${classes.debug}"
optimize="${classes.optimize}"
deprecation="${classes.deprecation}"
includes="${classes.includes}"
depend="${classes.depend}"
failonerror="no"
target="${classes.target-vm}">
<classpath>
<path refid="build.class.path"/>
</classpath>
</javac>
</target>
<!-- =========================================================== -->
<!-- Clean target. Removes the contents of the build and -->
<!-- staging directories, removes ejbs from myserver directory -->
<!-- =========================================================== -->
<target name="clean"
depends="init"
description="removes residue of previous builds">
<echo message="Removing residue of previous builds"/>
<delete verbose="true">
<fileset dir="${build.dir}"
includes="${clean.includes}"/>
</delete>
</target>
</project>