SixFive...

Using ANT from Eclipse

I have recently taken the plunge into ANT for use in deployment and doing some mundane tasks, and since I use Eclipse I have been playing with the integrated version that comes bundled. There were a few things that are not very well documented (or I could not find) that took me a while to […]
August 3, 2007 7:23 am

Using ANT from Eclipse

I have recently taken the plunge into ANT for use in deployment and doing some mundane tasks, and since I use Eclipse I have been playing with the integrated version that comes bundled. There were a few things that are not very well documented (or I could not find) that took me a while to figure out, so I though I would share.

Running an ANT task can be done from within Eclipse very easily. Eclipse recognises an ANT file as long as its called “build.xml”. You can then right click on the file and hit “Run As” > “Ant Build”. Eclipse will then execute it and push any output to the console (Window > Show View > Other > General > Console). An ANT build.xml file takes the following basic structure:

<?xml version="1.0"?>  
<project default="hello">   
   <target name="hello">    
      <echo message="hello world" />   
   </target>  
</project>

The project tag makes up the entire build. The target tag is like a holder for a bunch of tasks or one task. Inside of a target you can place any number of actions to take place. More on this later. You can set variables in an external file called build.properties, for example:

These variables can then be pulled in to the build task at run time using the property tag (this assumes the build.xml and build.properties are in the same directory)

You can also build up variable on-the-fly, here I have set up a build directory using the projectName

That is it for my quick primer to ANT, I will check out some more features in the coming days.

Leave a Comment