helloopensource

 

ant

Page history last edited by Paulo 1 yr ago
 

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:

  1. Go to Ant download page at: http://ant.apache.org/bindownload.cgi
  2. Download ant binary distribution file – e.g. apache-ant-1.7.0-bin.zip
  3. Unzip and install ant
  4. Set the ANT_HOME environment variable to the directory where you installed Ant.
    1. On Wondows: Systems Properties/ Advanced/ Environment Variables / System Variables/ New
  5. Add the Ant bin directory to your path.
  6. Make sure the jdk is properly installed – Ant uses Java, therefore the JDK must be properly installed.
  7. Make sure ant is working.
    1. Open a command prompt and execute ant –help
  8. Create a folder for your helloant project – e.g. C:\codebase\sample\helloant
  9. Create a HelloWorld.java class with the following code
    1. package mypackage;

       

      public class HelloWorld {

          public static void main(String[] args) {

              System.out.println("Hello World");

          }

      }

  10. Make sure the java class is located in the src\mypackage forlder (Full path:  C:\codebase\sample\helloant\src\mypackage)
  11. Create a build.xml text fiel with the following content:
    1. <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>

  12. Save your build.xml file to your project root (in my case C:\codebase\sample\helloant)
  13. Open a command prompt
  14. Go to your helloant project root (in my case C:\codebase\sample\helloant)
  15. Execute the following ant commands:
    • ant compile
    • ant jar
    • ant run
  16. You should get the results as depicted in the following picture

 

 

 

Comments (0)

You don't have permission to comment on this page.