Header Ads

  • Breaking Now

    What is ANT and how can one configure it?

    ANT is a Java based build tool and helps in automating whole of build process of a Java project.
    ANT uses an XML build file and by default it looks for a build file named build.xml from the directory it has been executed.

    A build.xml contains several targets e.g. creating or deleting directory structure, post compilation creation of jar or ear files, extracting/unzipping jar/ear files etc.One target can depend upon one or more targets and it can contain one or more tasks.

    One can download Apace Ant 1.7.1 from here.Once that is done, extract it any of your local drive. Set the system variables as follows:

    ANT_HOME =D:\apache-ant-1.7.1 (Here I have extracted the ANT ZIP at D drive)
    PATH = %ANT_HOME%\bin

    To ensure proper installation of ANT, go to command prompt and execute the command "ant - version", you will see the installed ant version.

    The execution of ANT file is done from the directory where build.xml resides and simply typing ant command on console and hit enter will start the execution of build file.

    The build.xml looks like as given below:
    <?xml version="1.0" ?>
    <project name="IQJava" default="compress"> <target name="compile"> <javac srcdir="com/iqjava/log4j"/> <echo> Compilation Complete! </echo> </target> <target name="compress" depends="compile"> <jar destfile="IQJava.jar" basedir="." includes="*.class" /> <echo> Building .jar file Complete! </echo> </target> </project>
    In the build.xml,<project> element is the root element, name attribute of this represents the name of the project.

    <target> element can exist multiple times within project element and each one of them represents a single stage. In the above build.xml, we have compile target element which contains two tasks, one - <echo> and the other <javac> which builds java files.

    The other target element 'compress' is dependent upon compile target element. It creates a jar file which includes all the .class files in current directory.

    The echo tasks just display messages on console.

    Post Top Ad

    Post Bottom Ad