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,

 Build.xml:

<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="agn.Hello"/>
            </manifest>
        </jar>
    </target>

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

</project>

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

Hello.java:

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……….!!!

147 total views, 1 views today

Leave a Reply

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