Prerequisite:
It is an xml file generally referred by build.xml
//build.xml
Run Build file:
We can run an ant file from
- Java environment installed (Make sure that environmental variables JAVA_HOME is set to the directory where your JDK is installed and JAVA_HOME is added to PATH)
- Download the latest stable version of Ant from the Ant web page http://ant.apache.org/
- Unzip the downloaded file into a directory in your local drive.
- Set environmental variables JAVA_HOME to your Java environment i.e to the directory where your JDK is installed.
- Set the ANT_HOME environment variable to the directory you unzipped Ant to or where you installed Ant.
- Add %ANT_HOME%/bin (for Windows) to your PATH
It is an xml file generally referred by build.xml
- Create a project(create package and test classes to be execute) or open existing project.
- Create a file namely 'build.xml' parallel to 'src' directory.
- Build file contains one project and at least one (default) target.
- The main components of ant are property, path, target, task etc.
//build.xml
- <project name="GoogleSearch" default="compile" basedir=".">
- <property name="src.dir" value="src" />
- <property name="lib.dir" value="lib" />
- <property name="build.loc" value="${build}" />
- <property name="classes.dir" value="${build.loc}/classes" />
- <path id="classpath">
- <pathelement location="${classes.dir}"/>
- <fileset dir="${lib.dir}" includes="*.jar"/>
- </path>
- <target name="compile">
- <javac destdir="${classes.dir}" includeantruntime="false" debug="true" srcdir="${src.dir}">
- <classpath refid="classpath"/>
- </javac>
- <echo> /* Compiled Directory Classes */ </echo>
- </target>
- </project>
Run Build file:
We can run an ant file from
- IDE(in my case eclipse) by right click on build.xml -> Run as -> Ant Build
- Command line by ant <target>
In the above sample build.xml, when it 'll run, it 'll execute the 'compile' target of build file which 'll compile all the classes under 'src' directory of the project.
No comments:
Post a Comment