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

ant

Create a folder structure

+
--src
----HelloAnt.java
--class
----HelloAnt.class
build.xml

HelloAnt.java

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

build.xml

<?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>

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

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

Build process

ant clean
ant compile
ant jar

Verify the build

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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s