Ant 20 Oct, 2005
Emboldened 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).
Official book chapter samplesBen Poole#