View RSS Feed

My Java Tips

Ant Project

Rate this Entry
by , 11-19-2011 at 05:43 PM (832 Views)
In this post, I will present a sample build.xml file for a simple Java "Hello, world" application and will explain the ANT project.

Java Code:
<project name="HelloWorld" default="compile">

  	<target name="compile">
    		<javac srcdir=".">

    	<target name="run" depends="jar">
    		<java classname="HelloWorld">                             classpath = "HelloWorld.jar" fork = "true" /&gt;
Please refer to the code above. You know that the Ant's buildfiles are written in XML. Each buildfile contains one project and at least one default target. Targets in turn contain task elements. Each task element of the buildfile can have an id attribute and can later be referred to by the value supplied to this. This value has to be unique.


A project is the top level element in an Ant script. It has three optional attributes:

name - is the name of the project
default - is the default target to use when no target is supplied
basedir - is the base directory from which all path calculations are done

Submit "Ant Project" to Facebook Submit "Ant Project" to Digg Submit "Ant Project" to Submit "Ant Project" to StumbleUpon Submit "Ant Project" to Google