Ant Hello world

Ant Hello world

Step 1: Create a folder named “ant build”  and get into that.

Step 2: Create a “build.xml” file inside “ant build” folder and copy the below code,



    <target name="clean">
        <delete dir="build"/>

    <target name="compile">
        <mkdir dir="build/classes"/>
        <javac srcdir="src" destdir="build/classes"/>

    <target name="jar">
        <mkdir dir="build/jar"/>
        <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
                <attribute name="Main-Class" value="agn.Hello"/>

    <target name="run">
        <java jar="build/jar/HelloWorld.jar" fork="true"/>


 Step 3: Create a folder named “src” inside ant folder and paste the java hello world source code (

package agn;
class Hello{
public static void main(String[] args){
System.out.println("Hello Javadomain");

Step 4: Open the command prompt and go to the “ant build” folder and run the following commands,

ant compile (to create the .class file)

ant jar (to create the jar file)

ant run (to run the hello world java program)

ant clean (to clean the ant screens)



Thanks for reading this post……….!!!

896 total views, 2 views today

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.