ANT (build automation tool):
Before we put our fingers on key board lets discuss about what the heck is this thing ANT ennnnn !, Being a java developer managing vast application life cycle is a devastating job ie.,(including support jars,class path entries,compiling,testing,debugging,packaging,executing), to wipe out the overhead one can use build automation tools and ant is one such tool.
so lets do it. things that are to be done before using this tool are downloading it from ant.apache.org/ it comes in various packaged formats choose the .zip binary, extract it to your disk, set environment variables
so that it's visible to the system.
i.e., if you are using windows boxes perform this. Go to command prompt and type
:/>set ANT_HOME=full path of the .zip extracted location
:/>set JAVA_HOME=full path of the jdk location
:/>set PATH=%ANT_HOME%\bin
Once you are done with this open your text editor and put your fingers nailed to the keyboard.
To perform the automation tasks with the developed application will have to create build.xml file or generate it unless you are using some kind of IDE. Basically the thing what happens is every thing lies in this xml file.
This file consists of some set of xml tags i.e.,(project,target,property,path,classpath,copy,....on and on and on).
The basic skeleton of build.xml file will be as follows
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="some project name" basedir="." default="some target name">
<target name="some target name">
.
.
.
some more xml tags
.
.
</project>
save the file in the root path of the application and from the cmd prompt invoke appropriate targets.
Simple ANT application:
Lets type our first ant application the hierarchy of the application would be some thing like shown below
Ant_Test_Application
|
src
|
test
|
geeks
|
code
|
First_Ant_Class.java
bin
|
build
|
classes
|
First_Ant_Class.class
jars
|
Ant_Test_Application.jar
build.xml
package test.geeks.code;
public class First_Ant_Class
{
public static void main(String...s)
{
System.out.println("HELLO ANT APPLICATION BEGINNERS !");
}
};
build.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="Ant_Test_Application" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="bin.dir" value="bin"/>
<property name="build.dir" value="${bin.dir}/build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jars"/>
<property name="main-class" value="test.geeks.code.First_Ant_Class"/>
<target name="clean">
<delete dir="${bin.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dri}" destdir="${classes.dir}"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}" />
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar"/>
<java jar="${jar.dir}/${ant.project.name}.jar" fork="false"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,jar,run"/>
</project>
save First_Ant_Class.java,build.xml into src and root directories respectively.,
now open the cmd prompt and go to the root directory of the application where build.xml is visible and type appropriate suffix target names to ant command
i.e.,
L:\anttests\somefolders\Ant_Test_Application\:>ant compile
it gives you a meaningful message for appropriate targets and finally BUILD SUCCESS if every thing is fine if not BUILD FAILED.
instead of go for step by step targets you can just type
L:\anttests\somefolders\Ant_Test_Application\:>ant
it's equivalent to ant compile jar run since we have mentioned the default attribute to main target which indeed is dependent upon jar,jar and run targets.
so thanks for now for going through the article ! soon i'll be publishing the subsequent tuts .
Before we put our fingers on key board lets discuss about what the heck is this thing ANT ennnnn !, Being a java developer managing vast application life cycle is a devastating job ie.,(including support jars,class path entries,compiling,testing,debugging,packaging,executing), to wipe out the overhead one can use build automation tools and ant is one such tool.
so lets do it. things that are to be done before using this tool are downloading it from ant.apache.org/ it comes in various packaged formats choose the .zip binary, extract it to your disk, set environment variables
so that it's visible to the system.
i.e., if you are using windows boxes perform this. Go to command prompt and type
:/>set ANT_HOME=full path of the .zip extracted location
:/>set JAVA_HOME=full path of the jdk location
:/>set PATH=%ANT_HOME%\bin
Once you are done with this open your text editor and put your fingers nailed to the keyboard.
To perform the automation tasks with the developed application will have to create build.xml file or generate it unless you are using some kind of IDE. Basically the thing what happens is every thing lies in this xml file.
This file consists of some set of xml tags i.e.,(project,target,property,path,classpath,copy,....on and on and on).
The basic skeleton of build.xml file will be as follows
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="some project name" basedir="." default="some target name">
<target name="some target name">
.
.
.
some more xml tags
.
.
</project>
save the file in the root path of the application and from the cmd prompt invoke appropriate targets.
Simple ANT application:
Lets type our first ant application the hierarchy of the application would be some thing like shown below
Ant_Test_Application
|
src
|
test
|
geeks
|
code
|
First_Ant_Class.java
bin
|
build
|
classes
|
First_Ant_Class.class
jars
|
Ant_Test_Application.jar
build.xml
package test.geeks.code;
public class First_Ant_Class
{
public static void main(String...s)
{
System.out.println("HELLO ANT APPLICATION BEGINNERS !");
}
};
build.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="Ant_Test_Application" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="bin.dir" value="bin"/>
<property name="build.dir" value="${bin.dir}/build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jars"/>
<property name="main-class" value="test.geeks.code.First_Ant_Class"/>
<target name="clean">
<delete dir="${bin.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dri}" destdir="${classes.dir}"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}" />
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar"/>
<java jar="${jar.dir}/${ant.project.name}.jar" fork="false"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,jar,run"/>
</project>
save First_Ant_Class.java,build.xml into src and root directories respectively.,
now open the cmd prompt and go to the root directory of the application where build.xml is visible and type appropriate suffix target names to ant command
i.e.,
L:\anttests\somefolders\Ant_Test_Application\:>ant compile
it gives you a meaningful message for appropriate targets and finally BUILD SUCCESS if every thing is fine if not BUILD FAILED.
instead of go for step by step targets you can just type
L:\anttests\somefolders\Ant_Test_Application\:>ant
it's equivalent to ant compile jar run since we have mentioned the default attribute to main target which indeed is dependent upon jar,jar and run targets.
so thanks for now for going through the article ! soon i'll be publishing the subsequent tuts .
a very useful and simple article !!!!!!!
ReplyDelete