Hello Ant
This Tutorial will show you how to download and install
Ant - an open source build tool.
Main Learning's
After following this tutorial you will learn how to:
- Download and install Ant
- Set up the required Ant System Variables
- Verify that the Ant is properly installed
- Compile, create a jar and run a HelloWorld.java class
Versions used:
- OS: Windows XP V1.6
- JDK version 1.6.0_3
- Ant version 1.7.0
Assumptions:
The JDK is properly installed
Tutorial Steps:
- Go to Ant download page at: http://ant.apache.org/bindownload.cgi
- Download ant binary distribution file – e.g. apache-ant-1.7.0-bin.zip
- Unzip and install ant

- Set the ANT_HOME environment variable to the directory where you installed Ant.
- On Wondows: Systems Properties/ Advanced/ Environment Variables / System Variables/ New


- Add the Ant bin directory to your path.


- Make sure the jdk is properly installed – Ant uses Java, therefore the JDK must be properly installed.
- Make sure ant is working.
- Open a command prompt and execute ant –help

- Create a folder for your helloant project – e.g. C:\codebase\sample\helloant
- Create a HelloWorld.java class with the following code
-
package mypackage;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
- Make sure the java class is located in the src\mypackage forlder (Full path: C:\codebase\sample\helloant\src\mypackage)
- Create a build.xml text fiel with the following content:
-
<project>
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes"/>
</target>
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="mypackage.HelloWorld"/>
</manifest>
</jar>
</target>
<target name="run">
<java jar="build/jar/HelloWorld.jar" fork="true"/>
</target>
</project>
- Save your build.xml file to your project root (in my case C:\codebase\sample\helloant)

- Open a command prompt
- Go to your helloant project root (in my case C:\codebase\sample\helloant)
- Execute the following ant commands:
- ant compile
- ant jar
- ant run
- You should get the results as depicted in the following picture

Comments (0)
You don't have permission to comment on this page.