Ant – the packaging system for Java – HowTo 2

Let’s be specific about java in this post. If you start reading this post afresh, please have a look at HowTo 1


Create a folder structure


public class HelloAnt{
public static void main(String [] args){
System.out.println("Hello Ant");


<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="HelloAnt" basedir="." default="jar">
<target name="clean" description="delete all classes">
<delete dir="classes"/>
<delete file="HelloAnt.jar"/>

<target name="compile" description="compiles the task">
<mkdir dir="classes"/>
<javac srcdir="src" destdir="classes"/>

<target name="jar" description="jars the task">
<jar destfile="HelloAnt.jar" basedir="classes"/>

Build process

ant clean
ant compile
ant jar

Verify the build

pandian@Kannan:~/Downloads/ant/sample$ java -cp HelloAnt.jar HelloAnt
Hello Ant

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s