Apache Ant project logoEmboldened by recent forays into the world of Maven I decided to actually look at Ant properly. Of course, if you mince around in Eclipse or MyEclipse like I do, then you already have some lovely Ant integration right there in yer IDE. Like me again though, that doesn’t mean you’ve actually tried it ;-)

Well, everything changed this week. Sick and tired of exporting projects in WAR format and then removing extraneous files, I decided to sit down and learn about targets and so forth, with a view to automating my wee builds. “Should be easy” thought I. After all, Ant gets used everywhere, so the silly little problems I need to solve will have been covered ad nauseam all over t’internet.

Or so you’d think.

Anyway, long story short, I came up with a little build.xml file which does exactly what I need for a particular project. The steps are:

  • In line with best practice, all folder references are variables defined “up-front”
  • Prepare build and distribution directories
  • Compile source code
  • Move compiled code, plus JSP and include files into the build directory
  • Create WAR file from build
  • Move “static” content (CSS, Javascript, images) into build directory, and place this in its own “static content” zip file
  • Copy WAR and zip files to the distribution target
  • Clean up

Simple! But it took a while to put together. So, I think I should share it. Feel free to lambast, comment, rip apart, whatever. There are plenty of comments in there for each target, and hopefully it will be useful as a starting point for your projects: I could have done with something like this when I started! Anyway, big thanks go to m’colleague Palin for his help and patience.

build.xml (3 KB. Updated 21 October for clarity and one typo).


  1. I don't think that the whole book is available on-line for free legitimately, but there are a fair few chapters out there as PDF files, and they're good ones. For example, this page neatly summarises three of them:

    Official book chapter samplesBen Poole#
  2. AppFuse does have a large build.xml that can be difficult to understand. However, AppFuse was largely inspired by Java Development with Ant - so if you read that book, most of it should make sense. If you're looking for a simpler example, you could check out the (much smaller) build.xml from Equinox.Matt Raible#

Comments on this post are now closed.


I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.