How to generate build.xml file
This example shows how to generate the build.xml file. You may say that build.xml file is the backbone of ANT (Another Neat Tool) technology. Each build.xml file contains only one project name and at least one target. The project tag has only three attributes: Project |
Attribute | Description | Requirement |
name | project name | not necessary |
default | target name which called by default | not necessary |
basedir | the base directory having all path, it contain absolute path | not necessary |
<project name="My Project" default="compile" basedir="."> |
An another tag is Target tag which has following five attributes:
Target |
Attribute | Description | Requirement |
name | target name | necessary |
depends | depends on another target | not necessary |
if | the name of the property that must be set in order for this target to execute. | not necessary |
unless | the name of the property that must not be set in order for this target to execute. | not necessary |
description | short description about target | not necessary |
<target name="buildWar" depends="init" description="build a war file"/> <target name="init" if="build"/><target name="init" unless="build"/> |
Next tag is property tag which has following four attribute:
Property |
Attribute | Description | Requirement |
name | name of the property, which is case-sensitive | not necessary |
value | name of task attribute, this is done by placing the property name between " ${ "name } " in the attribute value | necessary |
location | it contain property name | not necessary |
file | name of the property file | not necessary |
<property name="build" value="${build}"/> <property name="src" location="src"/> <property file="build.properties"/> |
<project name="My Project" default="jar" basedir="."> <property name="dir.src" value="src"/> <property name="dir.build" value="build"/> <property name="dir.dest" value="dest"/> <target name="clean" description="Removing the all generated files."> <delete dir="${dir.build}"/> <delete dir="${dir.dest}"/> </target> <target name="prepare" depends="clean"> <mkdir dir="${dir.build}"/> <mkdir dir="${dir.dest}"/> <mkdir dir="${dir.src}"/> </target> <target name="compile" depends="prepare" description="Compilation of all source code."> <javac srcdir="${dir.src}" destdir="${dir.build}"/> </target> <target name="jar" depends="compile" description="Generates Roseindia.jar file in to the 'dest' directory."> <jar jarfile="${dir.dest}/roseindia.jar" basedir="${dir.build}"/> </target> </project> |
The output shows that a jar file named roseindia.jar is created but in this jar file only manifest file is created. When you make a java file in the src folder and run with ant command, the jar file is created completely.
class Hello { public static void main(String args[]){ System.out.println("sandeep kumar suman"); } } |
No comments:
Post a Comment