1. 6/6/13 ANT - Build Tool
file:///D:/codin/ant/index.html 1/6
Codin | Home | Previous | Index | Next
ANT - Build Tool
# Introduction:
If we are developing only web application or enterprise application, we need to
follow below steps to run the application in the server:
1. Develope required files(.java, .jsp, .html etc)
2. Set the required .jar files into classpath.
3. Generate .class files.
4. Create required directory structure.
5. Generate .war file.
6. Start the server.
7. Deploy .war file into server.
8. To verify functionality of our application based on our project to
requirement.
9. Sometimes we need to stop server.
10. Sometimes we need to undeploy the application.
All the above steps are called as Build Process steps for Java application.
If we are manually follow all the above build process steps then it will increases the
project developement time and it is also increases the project cost.
To resolve these problems we need to use any one of build tool.
If we are using any of the build tool in our application to automate build process
steps then it will decreases project developement time and project developement
2. 6/6/13 ANT - Build Tool
file:///D:/codin/ant/index.html 2/6
cost.
Now we have two build tools in the market to automate build process steps for the
Java applications.
1. ANT, 2. MAVEN
1. ANT: ANT is a build tool, by using this tool we can automate build process
steps for Java applications.
-It is an open source framework which is given by Apache Software
Foundation.
-ANT build tool developed by using Java language.
Environment setup for the ANT:
1. Download ANT software (ant...zip file) from Apache website.
http://ant.apache.org
2. Extract the zip, and set two system environment variables:
ANT_HOME=E:apache-ant-1.8.4
PATH=......;E:apache-ant-1.8.4bin
3. To verify whether ANT successfully installed or not, we need to apen
command prompt and enter below command:
c:ant -version
If we want automate build process steps by using ANT build tool then we need to
provide some instructions about our build process steps in the form of XML tags to the
ANT build tool and that XML file name should be "build.xml" file and we need to save
the "build.xml" file in the project root directory.
To run build.xml file we need to open command prompt and go to where our
build.xml file existed.
Now to run build.xml file we have 2 ways:
3. 6/6/13 ANT - Build Tool
file:///D:/codin/ant/index.html 3/6
1. Executing target by target - To execute target by target we execute below
command:
Syntax: E:helloworldant <target name>
Example: E:helloworldant compile
2. Executing default target - If we want to execute default target we need to
use "default" attribute in <target> tag and we need to use "depends" attribute in
all the target tags.
Requirement2
# ANT build.xml with Properties file:
Sometimes we need to frequently change directory paths and file names in the
build.xml file, so that we need to change directory paths and file names if build.xml
file wherever we are using.
If we forget to change directory path and file name in any one of the place in
build.xml file then build will be failed.
To resolve these problems we need to define properties for the frequently used
files names and directory paths using <property> tag. Syntax:
build.xml
<project....>
4. 6/6/13 ANT - Build Tool
file:///D:/codin/ant/index.html 4/6
<propertyname="classes.dir"value="build/classes"/>
.....
</project>
If we want to use property names in the build.xml file then we need to expression
language (${<property-name>})
ANT build.xml file using Property file:
-Instead of defining properties in build.xml file directly we need to define all
the properties in separate file called "build.properties".
-We can define any name for the properties file, but we should define
meaningful name, and we need to store this "build.properties" file inside
where our build.xml file is exists.
-If we are using properties file to define the ANT build prperties then we need
to specify properties file name and path in build.xml file using <property> tag.
Syntax:
<project...>
...
<propertyfile="build.properties"/>
...
</project>
build.properties
classes.dir=build/classes
# Working with IDE:
All the latest IDE tools having ANT plugins so that we can directly run build.xml file
from the IDE tool.
Create any standalone project or web project in Eclipse and create build.xml file in
5. 6/6/13 ANT - Build Tool
file:///D:/codin/ant/index.html 5/6
project.
We have 3 ways to run the build.xml file in Eclipse:
1. Executing default target
2. Executing target by target
3. Executing build.xml file using "ANT view panel".
1. Executing default target: Right click on build.xml file->Run As->click on "ANT
Build".
2. Executing target by target: Right click on build.xml file->Run As->click on "ANT
Build..." check target name and click on Run button.
3. Executing using "ANT view panel": To run build.xml file using ANT view panel first
we need to open ANT view panel so to open ANT view panel we need:
Go to left Bottom corner of Eclipse->click on "show view as fast view"->click
on others->Expand ANT->Select "ANT"->click on OK.
-We need to add our project build.xml file to the ANT view panel.
Right click on "ANT view panel"->Add Build files->Browse our project->click on
build.xml->OK
Expand build.xml file and double click on required target to run.
Codin | Home | Previous | Index | Next