Ant build tool

Apache Ant is java based library and command line tool. Ant drive application using build xml file, control behavior of build, compile and run targets define in build xml file.

Basically ant build is a java based application. It can be Also  build non java applications such as C, C++, PHP, Python etc by passing their compile/interpreter. Ant is written in java so ant user can be develop their own library. Ant is easy to use it does not impose coding convention or directory layouts to the java projects.

Ant use a configuration xml file, default name of file is build.xml. ant directly call target define in build file. Targets can be define their dependencies, ant will automatically execute dependent target.

Here is a sample of ant buid.xml file.
<project name="SampleProject" default="" basedir=".">
   
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>

  <!-- Creating directory -->
  <target name="init" depends="clean">
    <mkdir dir="${build}"/>
      <mkdir dir="${dist}/lib"/>
  </target>

   <!-- Creating directory -->
   <target name="clean">  
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>
 
  <target name="compile" depends="init"  description="compile the source code" >   
      <javac
            srcdir="${src}/com/test"
            destdir="${build}"/>
  </target>

  <target name="dist" depends="compile"   description="generate tjar file" >  
    <jar
      jarfile="${dist}/lib/SampleProject.jar"
      basedir="${build}"/>
  </target>

</project>

For command line execution download Ant file from "https://ant.apache.org/bindownload.cgi".
Setup path in environment variable of your machine.
open command prompt and run command.

ant “targetname” 


No comments:

Post a Comment

Leave your comments, queries, suggestion I will try to provide solution