SlideShare a Scribd company logo
ANT Another Neat Tool
Objective Build Tool What is a build tool Why do we need a build tool ANT What is ANT Why ANT When to use ANT How ANT works Structure of Build File Installing and Running ANT More with ANT
What is a build tool A build tool is a programming utility that is used when building a new version of a program. It ensures that source files that have been updated and files that are dependent on them will be compiled into a newer version of the program.
Why do we need build tools Creating a product from source may take several steps: c ompile, link, copy files to various directories, remove intermediate files, generate documentation. It becomes problematic to do all these steps manually, first of all because it’s boring, second because it is error-prone. The objective should be an automated tool that does all the work for you. Type or click one command and create a final product. There are a couple of ways this can be done: Write a batch file or script The scripts tend to be hard to maintain Use a tool designed for the task Make Ant
What is ANT Java based free build tool from Apache - Build IN Java, USING Java, and FOR Java ANT uses XML based configuration “Build” file to drive its actions. It is easy to learn and to use, to create powerful Ant build files to compile and bundle applications in .jar, .ear, or .war files, and to deploy J2EE software applications
Why ANT Written in Java so it’s a Cross-Platform build tool, unlike MAKE which is UNIX based. Cross platform build files support developers working on different operating systems It is extended using Java Classes , unlike other models where it is extended using shell commands. This makes it easily extensible. Instead of writing shell commands, the configuration files are XML based which are easy to read and modify.
Why ANT Contd… Faster since each command is executed from within JVM. Each command is a thread unlike shell based buildtools where each command is a process. One-time setup hassle provides ea sy building of a project Ant's Debug Options are very helpful
When should one use ANT On any project with more than a few source files Every day for every build…
ANT Directory Structure (Recommended)
How ANT works Each build file has exactly one project. Each Build File is made up of at least one target.  Examples are: 'compile', ‘build', 'clean', etc. Each Target is made up of Tasks which are executed in a sequence Targets can have Dependencies Examples: 'install' depends on 'compile' Can handle cascading dependencies Each Dependency is handled only once
Structure of BUILD File <?xml version=&quot;1.0&quot;?> < project  name=&quot;Test&quot; default=&quot;jar&quot; basedir=&quot;.&quot;> < target  name=&quot;init&quot;> < property  file=”build.properties”/> <path id=&quot;classpath&quot;> <pathelement path=&quot;${weblogic.jar}&quot;/> </path> < /target > <target name=&quot;prepare&quot;  depends =&quot;init&quot;> < mkdir  dir=&quot;${build.dir}/META-INF&quot;/> </target>
Structure of BUILD File Contd... <target name=&quot;clean&quot; depends=&quot;init&quot;> < delete  dir=&quot;${build.dir}&quot;/> </target> <target  name=&quot;compile&quot;   depends =&quot;prepare&quot;> < javac  srcdir=&quot;${src.dir}&quot; destdir=&quot;${build.dir} classpathref=&quot;classpath&quot;/> </target> <target name=&quot;jar&quot; depends=&quot;compile&quot;> < jar  destfile=&quot;${dest.dir}/${name}.jar&quot; basedir=&quot;${build.dir}&quot;/> </target> </ project >
Project tag First statement should be <?xml version=&quot;1.0&quot;?> Top level XML tag is ‘project’; there should only be one project tag in a build file. Project tags specify the basic project attributes and have 3 properties:   - name : the name of the project.  - default target : the default target to use when no target is supplied.  - basedir : the base directory from which all path calculations are done. This attribute might be overridden by setting the &quot;basedir&quot; property beforehand. When this is done, it must be omitted in the project tag. If neither the attribute nor the property have been set, the parent directory of the build file will be used.  - All three are optional <project name=&quot;Test&quot; default=&quot;build&quot; basedir=&quot;.&quot;>
Targets A project is made up of a number of targets that tell Ant what it should do like create initial directories, compile source, create javadoc, create jar files, etc. Targets consist of a series of  tasks  that are specific actions for ant to take When starting Ant, you can select which target(s) you want to have executed. When no target is given, the project's default is used.  Targets have these attributes name (required) : All targets must have a name such as “compile”, “init”,  “clean” depends (comma separated list of other targets) : Targets can depend on each other. A target that depends on another target will demand that the other target get executed first
Targets Contd… description : Can have a “description” to explain the target's purpose If : “if” will execute a target only if a given property is defined Unless : “unless” will only execute a target if a given property is not defined Each target is only executed once regardless of the number of other targets that depend on it Overall structure of targets:   <target name=&quot;A&quot;/>  <target name=&quot;B&quot; depends=&quot;A&quot;/>  <target name=&quot;C&quot; depends=&quot;B&quot;/>  <target name=&quot;D&quot; depends=&quot;C,B,A&quot;/>   <target name=&quot;build-module-A&quot; if=&quot;module-A-present&quot;/> <target name=&quot;build-own-fake-module-A&quot; unless=&quot;module-A-present&quot;/> Note : If no if and no unless attribute is present, the target will always be executed.
Useful Target Definitions Init :  Sets up properties that will be used throughout the build file. Properties can be set directly or by specifying a properties file. Prepare :  Create any directory structure which is needed. Clean :  clean is useful for enabling clean builds. Generally just deletes stuff from previous runs. (ant clean build) Compile :  Compile some/all of your source files in this target Jar :  Creates a jar file from the stuff you’ve built
Tasks Each target comprises one or more tasks Task is a piece of executable Java code (e.g. javac, jar, etc) Tasks do the actual “build” work in Ant Ant has core (built in) tasks, optional tasks and the ability to create own tasks
Tasks Contd… Example: < name   attribute1 =&quot; value1 &quot;  attribute2 =&quot; value2 &quot; ... />  <target name=&quot;prepare&quot; depends=&quot;init“ > < mkdir  dir=&quot;${build}&quot; /> </target> <target name=&quot;build&quot; depends=&quot;copy&quot; > < javac  srcdir=&quot;src&quot; destdir=&quot;${build}&quot;> </javac> </target>
Tasks Contd… Archive Tasks Compile Tasks Deployment Tasks Documentation Tasks File Tasks Property Tasks
Tasks Contd… javac - The javac task compiles Java source into class files,just as the javac command-line tool does. Ant will recompile only those files that have changed. java - Execute a Java class javadoc  -  Generates JavaDoc from your source files jar (and war) - Create JAR files mkdir - Makes a directory copy - Copies files to specified location   exec - allows different commands to be executed based on the OS it is executing on.
Tasks Contd… delete - Deletes specified files  parallel  -  Runs two or more Ant tasks (not targets)  simultaneously in separate threads Import - Includes another build file into the current file echo -  Prints a message to the console (default) or a file antcall  -  Calls another target within the same build file ant  -  Calls another target on a different build file FTP - lists, gets, puts and deletes files on an FTP server Note : You can also write your own tasks.
Properties Property has a name and a value; the name is case-sensitive. Properties may be used in the value of task attributes. This is done by placing the property name between &quot;${&quot; and &quot;}&quot; in the attribute value.  Example: <property name=“src” value=“/home/src”/> <property file=“build.properties”/> Can use ${src} anywhere in build file to denote /home/src Ant provides access to all system properties as if defined by the <property> task
Path Structures Ant provides means to set various environment variables like PATH and CLASSPATH. Example of setting CLASSPATH: <classpath>  <pathelement path=&quot;${classpath}&quot;/>  <pathelement location=&quot;lib/helper.jar&quot;/>  </classpath
Command Line Arguments -buildfile/ -file / -f buildfile   – specify build file to use targetname – specify target to run (instead of running default) -debug – prints debug information  -logfile filename  –  log the output in the given file -D<property>=<value> -  use value for given property -help, -h  -version : print the version information
Installing Ant Download Ant binary distribution from: http://ant.apache.org/bindownload.cgi Set ANT_HOME to where you installed Ant Include $ANT_HOME/bin in PATH  Make sure JAVA_HOME is set to point to JDK Do not ever set CLASSPATH. Ant does not need it, it only causes confusion and breaks things.  Assume Ant is installed in c:\ant\. The following sets up the environment: set ANT_HOME=c:\ant  set JAVA_HOME=c:\j2sdk1.6.0_24 set PATH=%PATH%;%ANT_HOME%\bin Note :  To build and use Ant, you must have a JAXP-compliant XML parser installed and available on your classpath, such as Xerces.
Running Ant Type “ant” at the command line Automatically looks for build.xml file in current directory to run Type “ant –buildfile  buildfile.xml ” to specify another build file to run ant –help lists other command-line options
More with ANT <mail> : using this task a mail carrying the build result can be sent to the specified recipients. Recording the output :  <record name=&quot;${ant.file}.log“ loglevel=&quot;verbose&quot; />
References http://ant.apache.org/manual http://ant.apache.org/faq.html http://en.wikipedia.org/wiki/Apache_Ant

More Related Content

ODP
Ant User Guide
PPT
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
PPT
Rich faces
PPT
Processing XML with Java
PPT
Android | Busy Java Developers Guide to Android: UI | Ted Neward
ODP
Object Oriented Design Patterns for PHP
ZIP
Looking into HTML5
ODP
JavaScript and jQuery Fundamentals
Ant User Guide
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Rich faces
Processing XML with Java
Android | Busy Java Developers Guide to Android: UI | Ted Neward
Object Oriented Design Patterns for PHP
Looking into HTML5
JavaScript and jQuery Fundamentals

What's hot (20)

PPT
Boston Computing Review - Java Server Pages
PDF
Html 5 in a big nutshell
PDF
Design attern in php
PPT
Unified Expression Language
PPTX
All the support you need. Support libs in Android
PPT
JSF Custom Components
PPT
PDF
How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016
PDF
WordCamp ABQ 2013: Making the leap from Designer to Designer/Developer
PDF
Wordcamp abq cf-cpt
PDF
Annotations in PHP, They Exist.
PPT
Declarative Development Using Annotations In PHP
PDF
Javascript Best Practices
PDF
Design patterns revisited with PHP 5.3
ODP
JavaScript APIs In Focus
PPT
WordPress development paradigms, idiosyncrasies and other big words
PPT
Web Applications and Deployment
PPT
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
PPT
What's new and exciting with JSF 2.0
PDF
Getting started with go - Florin Patan - Codemotion Milan 2016
Boston Computing Review - Java Server Pages
Html 5 in a big nutshell
Design attern in php
Unified Expression Language
All the support you need. Support libs in Android
JSF Custom Components
How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016
WordCamp ABQ 2013: Making the leap from Designer to Designer/Developer
Wordcamp abq cf-cpt
Annotations in PHP, They Exist.
Declarative Development Using Annotations In PHP
Javascript Best Practices
Design patterns revisited with PHP 5.3
JavaScript APIs In Focus
WordPress development paradigms, idiosyncrasies and other big words
Web Applications and Deployment
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
What's new and exciting with JSF 2.0
Getting started with go - Florin Patan - Codemotion Milan 2016
Ad

Similar to Ant - Another Neat Tool (20)

PPT
Introduction To Ant
PPT
Using Ant To Build J2 Ee Applications
PPT
PPT
Apache Ant
PDF
Deploy Flex with Apache Ant
PPT
Intro to-ant
PPT
Introduction To Ant1
PPT
Apache Ant
PPT
Apache Ant
PPTX
Apache ant
PDF
Ant_quick_guide
PPT
PPTX
PDF
Introduction to Apache Ant
PDF
PPTX
Apache ant
PPT
PPT
Introduction to Software Build Technology
PPTX
Java build tools
Introduction To Ant
Using Ant To Build J2 Ee Applications
Apache Ant
Deploy Flex with Apache Ant
Intro to-ant
Introduction To Ant1
Apache Ant
Apache Ant
Apache ant
Ant_quick_guide
Introduction to Apache Ant
Apache ant
Introduction to Software Build Technology
Java build tools
Ad

Recently uploaded (20)

PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Unlock new opportunities with location data.pdf
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPT
Geologic Time for studying geology for geologist
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPT
What is a Computer? Input Devices /output devices
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
STKI Israel Market Study 2025 version august
DOCX
search engine optimization ppt fir known well about this
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
observCloud-Native Containerability and monitoring.pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Unlock new opportunities with location data.pdf
A contest of sentiment analysis: k-nearest neighbor versus neural network
Geologic Time for studying geology for geologist
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
What is a Computer? Input Devices /output devices
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
STKI Israel Market Study 2025 version august
search engine optimization ppt fir known well about this
Taming the Chaos: How to Turn Unstructured Data into Decisions
WOOl fibre morphology and structure.pdf for textiles
Benefits of Physical activity for teenagers.pptx
DP Operators-handbook-extract for the Mautical Institute
sustainability-14-14877-v2.pddhzftheheeeee
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Zenith AI: Advanced Artificial Intelligence
1 - Historical Antecedents, Social Consideration.pdf
observCloud-Native Containerability and monitoring.pptx

Ant - Another Neat Tool

  • 2. Objective Build Tool What is a build tool Why do we need a build tool ANT What is ANT Why ANT When to use ANT How ANT works Structure of Build File Installing and Running ANT More with ANT
  • 3. What is a build tool A build tool is a programming utility that is used when building a new version of a program. It ensures that source files that have been updated and files that are dependent on them will be compiled into a newer version of the program.
  • 4. Why do we need build tools Creating a product from source may take several steps: c ompile, link, copy files to various directories, remove intermediate files, generate documentation. It becomes problematic to do all these steps manually, first of all because it’s boring, second because it is error-prone. The objective should be an automated tool that does all the work for you. Type or click one command and create a final product. There are a couple of ways this can be done: Write a batch file or script The scripts tend to be hard to maintain Use a tool designed for the task Make Ant
  • 5. What is ANT Java based free build tool from Apache - Build IN Java, USING Java, and FOR Java ANT uses XML based configuration “Build” file to drive its actions. It is easy to learn and to use, to create powerful Ant build files to compile and bundle applications in .jar, .ear, or .war files, and to deploy J2EE software applications
  • 6. Why ANT Written in Java so it’s a Cross-Platform build tool, unlike MAKE which is UNIX based. Cross platform build files support developers working on different operating systems It is extended using Java Classes , unlike other models where it is extended using shell commands. This makes it easily extensible. Instead of writing shell commands, the configuration files are XML based which are easy to read and modify.
  • 7. Why ANT Contd… Faster since each command is executed from within JVM. Each command is a thread unlike shell based buildtools where each command is a process. One-time setup hassle provides ea sy building of a project Ant's Debug Options are very helpful
  • 8. When should one use ANT On any project with more than a few source files Every day for every build…
  • 9. ANT Directory Structure (Recommended)
  • 10. How ANT works Each build file has exactly one project. Each Build File is made up of at least one target. Examples are: 'compile', ‘build', 'clean', etc. Each Target is made up of Tasks which are executed in a sequence Targets can have Dependencies Examples: 'install' depends on 'compile' Can handle cascading dependencies Each Dependency is handled only once
  • 11. Structure of BUILD File <?xml version=&quot;1.0&quot;?> < project name=&quot;Test&quot; default=&quot;jar&quot; basedir=&quot;.&quot;> < target name=&quot;init&quot;> < property file=”build.properties”/> <path id=&quot;classpath&quot;> <pathelement path=&quot;${weblogic.jar}&quot;/> </path> < /target > <target name=&quot;prepare&quot; depends =&quot;init&quot;> < mkdir dir=&quot;${build.dir}/META-INF&quot;/> </target>
  • 12. Structure of BUILD File Contd... <target name=&quot;clean&quot; depends=&quot;init&quot;> < delete dir=&quot;${build.dir}&quot;/> </target> <target name=&quot;compile&quot; depends =&quot;prepare&quot;> < javac srcdir=&quot;${src.dir}&quot; destdir=&quot;${build.dir} classpathref=&quot;classpath&quot;/> </target> <target name=&quot;jar&quot; depends=&quot;compile&quot;> < jar destfile=&quot;${dest.dir}/${name}.jar&quot; basedir=&quot;${build.dir}&quot;/> </target> </ project >
  • 13. Project tag First statement should be <?xml version=&quot;1.0&quot;?> Top level XML tag is ‘project’; there should only be one project tag in a build file. Project tags specify the basic project attributes and have 3 properties: - name : the name of the project. - default target : the default target to use when no target is supplied. - basedir : the base directory from which all path calculations are done. This attribute might be overridden by setting the &quot;basedir&quot; property beforehand. When this is done, it must be omitted in the project tag. If neither the attribute nor the property have been set, the parent directory of the build file will be used. - All three are optional <project name=&quot;Test&quot; default=&quot;build&quot; basedir=&quot;.&quot;>
  • 14. Targets A project is made up of a number of targets that tell Ant what it should do like create initial directories, compile source, create javadoc, create jar files, etc. Targets consist of a series of tasks that are specific actions for ant to take When starting Ant, you can select which target(s) you want to have executed. When no target is given, the project's default is used. Targets have these attributes name (required) : All targets must have a name such as “compile”, “init”, “clean” depends (comma separated list of other targets) : Targets can depend on each other. A target that depends on another target will demand that the other target get executed first
  • 15. Targets Contd… description : Can have a “description” to explain the target's purpose If : “if” will execute a target only if a given property is defined Unless : “unless” will only execute a target if a given property is not defined Each target is only executed once regardless of the number of other targets that depend on it Overall structure of targets: <target name=&quot;A&quot;/> <target name=&quot;B&quot; depends=&quot;A&quot;/> <target name=&quot;C&quot; depends=&quot;B&quot;/> <target name=&quot;D&quot; depends=&quot;C,B,A&quot;/> <target name=&quot;build-module-A&quot; if=&quot;module-A-present&quot;/> <target name=&quot;build-own-fake-module-A&quot; unless=&quot;module-A-present&quot;/> Note : If no if and no unless attribute is present, the target will always be executed.
  • 16. Useful Target Definitions Init : Sets up properties that will be used throughout the build file. Properties can be set directly or by specifying a properties file. Prepare : Create any directory structure which is needed. Clean : clean is useful for enabling clean builds. Generally just deletes stuff from previous runs. (ant clean build) Compile : Compile some/all of your source files in this target Jar : Creates a jar file from the stuff you’ve built
  • 17. Tasks Each target comprises one or more tasks Task is a piece of executable Java code (e.g. javac, jar, etc) Tasks do the actual “build” work in Ant Ant has core (built in) tasks, optional tasks and the ability to create own tasks
  • 18. Tasks Contd… Example: < name attribute1 =&quot; value1 &quot; attribute2 =&quot; value2 &quot; ... /> <target name=&quot;prepare&quot; depends=&quot;init“ > < mkdir dir=&quot;${build}&quot; /> </target> <target name=&quot;build&quot; depends=&quot;copy&quot; > < javac srcdir=&quot;src&quot; destdir=&quot;${build}&quot;> </javac> </target>
  • 19. Tasks Contd… Archive Tasks Compile Tasks Deployment Tasks Documentation Tasks File Tasks Property Tasks
  • 20. Tasks Contd… javac - The javac task compiles Java source into class files,just as the javac command-line tool does. Ant will recompile only those files that have changed. java - Execute a Java class javadoc - Generates JavaDoc from your source files jar (and war) - Create JAR files mkdir - Makes a directory copy - Copies files to specified location exec - allows different commands to be executed based on the OS it is executing on.
  • 21. Tasks Contd… delete - Deletes specified files parallel - Runs two or more Ant tasks (not targets) simultaneously in separate threads Import - Includes another build file into the current file echo - Prints a message to the console (default) or a file antcall - Calls another target within the same build file ant - Calls another target on a different build file FTP - lists, gets, puts and deletes files on an FTP server Note : You can also write your own tasks.
  • 22. Properties Property has a name and a value; the name is case-sensitive. Properties may be used in the value of task attributes. This is done by placing the property name between &quot;${&quot; and &quot;}&quot; in the attribute value. Example: <property name=“src” value=“/home/src”/> <property file=“build.properties”/> Can use ${src} anywhere in build file to denote /home/src Ant provides access to all system properties as if defined by the <property> task
  • 23. Path Structures Ant provides means to set various environment variables like PATH and CLASSPATH. Example of setting CLASSPATH: <classpath> <pathelement path=&quot;${classpath}&quot;/> <pathelement location=&quot;lib/helper.jar&quot;/> </classpath
  • 24. Command Line Arguments -buildfile/ -file / -f buildfile – specify build file to use targetname – specify target to run (instead of running default) -debug – prints debug information -logfile filename – log the output in the given file -D<property>=<value> - use value for given property -help, -h -version : print the version information
  • 25. Installing Ant Download Ant binary distribution from: http://ant.apache.org/bindownload.cgi Set ANT_HOME to where you installed Ant Include $ANT_HOME/bin in PATH Make sure JAVA_HOME is set to point to JDK Do not ever set CLASSPATH. Ant does not need it, it only causes confusion and breaks things. Assume Ant is installed in c:\ant\. The following sets up the environment: set ANT_HOME=c:\ant set JAVA_HOME=c:\j2sdk1.6.0_24 set PATH=%PATH%;%ANT_HOME%\bin Note : To build and use Ant, you must have a JAXP-compliant XML parser installed and available on your classpath, such as Xerces.
  • 26. Running Ant Type “ant” at the command line Automatically looks for build.xml file in current directory to run Type “ant –buildfile buildfile.xml ” to specify another build file to run ant –help lists other command-line options
  • 27. More with ANT <mail> : using this task a mail carrying the build result can be sent to the specified recipients. Recording the output : <record name=&quot;${ant.file}.log“ loglevel=&quot;verbose&quot; />