Ant build tool1


Published on

1/2 This is introduction of ANT build tool. See ANT examples:

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Ant build tool1

  1. 1. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/index.html 1/6Codin | Home | Previous | Index | NextANT - Build Tool# Introduction:If we are developing only web application or enterprise application, we need tofollow 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 torequirement.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 theproject 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 processsteps then it will decreases project developement time and project developement
  2. 2. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/index.html 2/6cost.Now we have two build tools in the market to automate build process steps for theJava applications.1. ANT, 2. MAVEN1. ANT: ANT is a build tool, by using this tool we can automate build processsteps for Java applications.-It is an open source framework which is given by Apache SoftwareFoundation.-ANT build tool developed by using Java language.Environment setup for the ANT:1. Download ANT software ( file) from Apache website.http://ant.apache.org2. Extract the zip, and set two system environment variables:ANT_HOME=E:apache-ant-1.8.4PATH=......;E:apache-ant-1.8.4bin3. To verify whether ANT successfully installed or not, we need to apencommand prompt and enter below command:c:ant -versionIf we want automate build process steps by using ANT build tool then we need toprovide some instructions about our build process steps in the form of XML tags to theANT build tool and that XML file name should be "build.xml" file and we need to savethe "build.xml" file in the project root directory.To run build.xml file we need to open command prompt and go to where ourbuild.xml file existed.Now to run build.xml file we have 2 ways:
  3. 3. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/index.html 3/61. Executing target by target - To execute target by target we execute belowcommand:Syntax: E:helloworldant <target name>Example: E:helloworldant compile2. Executing default target - If we want to execute default target we need touse "default" attribute in <target> tag and we need to use "depends" attribute inall the target tags.Requirement2# ANT build.xml with Properties file:Sometimes we need to frequently change directory paths and file names in thebuild.xml file, so that we need to change directory paths and file names if build.xmlfile wherever we are using.If we forget to change directory path and file name in any one of the place inbuild.xml file then build will be failed.To resolve these problems we need to define properties for the frequently usedfiles names and directory paths using <property> tag. Syntax:build.xml<project....>
  4. 4. 6/6/13 ANT - Build Toolfile:///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 expressionlanguage (${<property-name>})ANT build.xml file using Property file:-Instead of defining properties in build.xml file directly we need to define allthe properties in separate file called "".-We can define any name for the properties file, but we should definemeaningful name, and we need to store this "" file insidewhere our build.xml file is exists.-If we are using properties file to define the ANT build prperties then we needto specify properties file name and path in build.xml file using <property> tag.Syntax:<project...>...<propertyfile=""/>...</project>build.propertiesclasses.dir=build/classes# Working with IDE:All the latest IDE tools having ANT plugins so that we can directly run build.xml filefrom the IDE tool.Create any standalone project or web project in Eclipse and create build.xml file in
  5. 5. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/index.html 5/6project.We have 3 ways to run the build.xml file in Eclipse:1. Executing default target2. Executing target by target3. Executing build.xml file using "ANT view panel".1. Executing default target: Right click on build.xml file->Run As->click on "ANTBuild".2. Executing target by target: Right click on build.xml file->Run As->click on "ANTBuild..." check target name and click on Run button.3. Executing using "ANT view panel": To run build.xml file using ANT view panel firstwe 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"->clickon 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 onbuild.xml->OKExpand build.xml file and double click on required target to run.Codin | Home | Previous | Index | Next
  6. 6. 6/6/13 ANT - Build Toolfile:///D:/codin/ant/index.html 6/6© Rohit Rakshit