SlideShare a Scribd company logo
Ali Bahu
12/24/2012
APACHE ANT
INTRODUCTION
 A build tool can be used to automate certain repetitive tasks for
example compiling source code, running software tests and
creating files and documentation for the software deployment.
 Build tools typically run without a graphical user interface.
 Popular build tools used by Java developers are Apache Ant and
Maven.
APACHE ANT OVERVIEW
 Apache Ant (Ant) is a general purpose build tool. Ant is an abbreviation for
“Another Neat Tool”.
 Ant is primarily used for building and deploying Java projects.
 A Java build process typically includes:
 the compilation of the Java source code into Java bytecode
 creation of the .jar file for the distribution of the code
 creation of the Javadoc documentation
 Ant uses an xml file for its configuration. This file is usually called build.xml.
Ant builds are based on three blocks: tasks, targets and extension points.
 A task is a unit of work which should be performed and are small, atomic
steps, for example compile source code or create Javadoc. Tasks can be
grouped into targets.
 A target can be directly invoked via Ant. Targets can specify their
dependencies. Ant will automatically execute dependent targets. For example
if target A depends on B, than Ant will first perform B and then A. You can
specify the default target in your build.xml file. Ant will execute this target, if
no explicit target is specified.
HOW TO USE APACHE ANT
 Create a Java Project called com.fedex.build.ant.first in Eclipses.
Create a package called test.
package test;
public class MyTest
{
public int multi(int number1, int number2)
{
return number1 * number2;
}
}
package test;
import test.MyTest;
public class Main
{
public static void main(String[] args) {
MyTest test = new MyTest();
System.out.println("Result is: " + test.multi(5,
10));
}
}
CREATE BUILD.XML FILE & RUN FROM
ECLIPSE
 Click on the build.xml file to review and understand it.
 Running from Eclipse i.e.
 Running From Command Line:
Open a command line and switch
to your project directory. Type in
"ant" or "ant -f build.xml" to start
the build process.
APACHE ANT CLASSPATH
 Ant also allows to create classpath containers and use them in
tasks. The following build_classpath.xml from a project called
com.fedex.build.ant.classpath demonstrates this concept:
 To print the classpath for debugging:
<!-- Write the classpath to the console. Helpful for debugging -->
<!-- Create one line per classpath element-->
<pathconvert pathsep="${line.separator}" property="echo.classpath" refid="junit.class.path">
</pathconvert>
<!-- Write the result to the console -->
<echo message="The following classpath is associated with junit.class.path" />
<echo message="${echo.classpath}" />
RUNNING JUNITS VIA ANT
 Ant allows to run JUnit tests. Ant defines JUnit task. You only need to
include the junit.jar and the compiled classes into the classpath for
Ant and then you can run JUnit tests. Below is an example:
 You can run this JUnit unit test via the following build_junit.xml. This
example assumes that the JUnit jar "junit.jar" is located in “lib” folder.
package test;
import math.MyMath;
import org.junit.Test;
import static
org.junit.Assert.assertEquals;
public class MyMathTest {
@Test
public void testMulti() {
MyMath math = new MyMath();
assertEquals(50, math.multi(5, 10));
}
}
ANT TIPS
 Eclipse has an ant editor which make the editing of ant file very easy by
providing syntax checking of the build file. Eclipse has also a ant view. In this
view you execute ant files via double-clicking on the target.
 Apache Ant allows to convert relative paths to absolute paths i.e.
<property name="my.config" value="../my-config.xml"/>
<makeurl file="${my.config}" property="my.config.url"/>
 Ant can be used to replace text based on regular expressions i.e.
<target name="regular-expressions">
<!-- Replace tabs with two spaces -->
<replaceregexp flags="gs">
<regexp pattern="(t)" />
<substitution expression=" " />
<fileset dir="${outputtmp.dir}/">
<include name="**/*" /> </fileset>
</replaceregexp>
</target>

More Related Content

PPT
Apache Ant
PPTX
Apache Ant
PPT
Apache Ant
PPT
Apache Ant
PPTX
Apache ant
PPTX
Apache ant
PDF
Introduction to Apache Ant
PPT
Using Ant To Build J2 Ee Applications
Apache Ant
Apache Ant
Apache Ant
Apache Ant
Apache ant
Apache ant
Introduction to Apache Ant
Using Ant To Build J2 Ee Applications

What's hot (19)

PPTX
EclipseMAT
PPT
PDF
Mastering Maven 2.0 In 1 Hour V1.3
PDF
Ant tutorial
PDF
Maven 3.0 at Øredev
PPTX
Creating a Plug-In Architecture
PPT
Introduction To Ant1
PPT
Ant - Another Neat Tool
ODP
dJango
PDF
Deploy Flex with Apache Ant
PDF
Jumping Into WordPress Plugin Programming
ODP
Intro To Spring Python
PDF
Django Introduction & Tutorial
PDF
Web develop in flask
PDF
Building a Dynamic Website Using Django
ODP
Django for Beginners
PDF
Building domain-specific testing tools : lessons learned from the Apache Slin...
PDF
RSpec 3.0: Under the Covers
ODP
Introduction to Django
EclipseMAT
Mastering Maven 2.0 In 1 Hour V1.3
Ant tutorial
Maven 3.0 at Øredev
Creating a Plug-In Architecture
Introduction To Ant1
Ant - Another Neat Tool
dJango
Deploy Flex with Apache Ant
Jumping Into WordPress Plugin Programming
Intro To Spring Python
Django Introduction & Tutorial
Web develop in flask
Building a Dynamic Website Using Django
Django for Beginners
Building domain-specific testing tools : lessons learned from the Apache Slin...
RSpec 3.0: Under the Covers
Introduction to Django
Ad

Viewers also liked (16)

PPTX
PPT
Introduction to Apache Ant
PPT
Apache ANT vs Apache Maven
PDF
PDF
Apache Ant
PDF
Docker Basics
PDF
docker installation and basics
PPT
Apache ANT
PDF
Java Builds with Maven and Ant
PPTX
Docker Basics
PDF
Trends at JavaOne 2016: Microservices, Docker and Cloud-Native Middleware
PDF
Blockchain + Streaming Analytics with Ethereum and TIBCO StreamBase
PDF
Flogo - A Golang-powered Open Source IoT Integration Framework (Gophercon)
PDF
Docker by Example - Basics
PDF
How to deploy PHP projects with docker
PPTX
Docker 101 - Nov 2016
Introduction to Apache Ant
Apache ANT vs Apache Maven
Apache Ant
Docker Basics
docker installation and basics
Apache ANT
Java Builds with Maven and Ant
Docker Basics
Trends at JavaOne 2016: Microservices, Docker and Cloud-Native Middleware
Blockchain + Streaming Analytics with Ethereum and TIBCO StreamBase
Flogo - A Golang-powered Open Source IoT Integration Framework (Gophercon)
Docker by Example - Basics
How to deploy PHP projects with docker
Docker 101 - Nov 2016
Ad

Similar to Apache Ant (20)

PPT
Comparative Development Methodologies
PDF
Java ant tutorial
PPTX
Database Management Assignment Help
PPTX
Junit and cactus
PPT
N Unit Presentation
PPTX
8-testing.pptx
PPT
Testing Options in Java
PDF
Maven and j unit introduction
PPTX
Jack borden jb471909_junit
PPTX
Jack borden jb471909_junit1
PPTX
Chapter 2.1
PPT
Unit Testing RPG with JUnit
PPTX
Java/Servlet/JSP/JDBC
DOCX
Test Driven Development
PPTX
javaprogramming framework-ppt frame.pptx
DOCX
Integrate UFT with Jenkins Guide
PPS
JUnit Presentation
PPS
J unit presentation
PPTX
C# Security Testing and Debugging
PDF
Unit Testing on Android - Droidcon Berlin 2015
Comparative Development Methodologies
Java ant tutorial
Database Management Assignment Help
Junit and cactus
N Unit Presentation
8-testing.pptx
Testing Options in Java
Maven and j unit introduction
Jack borden jb471909_junit
Jack borden jb471909_junit1
Chapter 2.1
Unit Testing RPG with JUnit
Java/Servlet/JSP/JDBC
Test Driven Development
javaprogramming framework-ppt frame.pptx
Integrate UFT with Jenkins Guide
JUnit Presentation
J unit presentation
C# Security Testing and Debugging
Unit Testing on Android - Droidcon Berlin 2015

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
cuic standard and advanced reporting.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
A Presentation on Artificial Intelligence
Per capita expenditure prediction using model stacking based on satellite ima...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25 Week I
Digital-Transformation-Roadmap-for-Companies.pptx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Building Integrated photovoltaic BIPV_UPV.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine learning based COVID-19 study performance prediction
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
NewMind AI Monthly Chronicles - July 2025
MYSQL Presentation for SQL database connectivity
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
A Presentation on Artificial Intelligence

Apache Ant

  • 2. INTRODUCTION  A build tool can be used to automate certain repetitive tasks for example compiling source code, running software tests and creating files and documentation for the software deployment.  Build tools typically run without a graphical user interface.  Popular build tools used by Java developers are Apache Ant and Maven.
  • 3. APACHE ANT OVERVIEW  Apache Ant (Ant) is a general purpose build tool. Ant is an abbreviation for “Another Neat Tool”.  Ant is primarily used for building and deploying Java projects.  A Java build process typically includes:  the compilation of the Java source code into Java bytecode  creation of the .jar file for the distribution of the code  creation of the Javadoc documentation  Ant uses an xml file for its configuration. This file is usually called build.xml. Ant builds are based on three blocks: tasks, targets and extension points.  A task is a unit of work which should be performed and are small, atomic steps, for example compile source code or create Javadoc. Tasks can be grouped into targets.  A target can be directly invoked via Ant. Targets can specify their dependencies. Ant will automatically execute dependent targets. For example if target A depends on B, than Ant will first perform B and then A. You can specify the default target in your build.xml file. Ant will execute this target, if no explicit target is specified.
  • 4. HOW TO USE APACHE ANT  Create a Java Project called com.fedex.build.ant.first in Eclipses. Create a package called test. package test; public class MyTest { public int multi(int number1, int number2) { return number1 * number2; } } package test; import test.MyTest; public class Main { public static void main(String[] args) { MyTest test = new MyTest(); System.out.println("Result is: " + test.multi(5, 10)); } }
  • 5. CREATE BUILD.XML FILE & RUN FROM ECLIPSE  Click on the build.xml file to review and understand it.  Running from Eclipse i.e.  Running From Command Line: Open a command line and switch to your project directory. Type in "ant" or "ant -f build.xml" to start the build process.
  • 6. APACHE ANT CLASSPATH  Ant also allows to create classpath containers and use them in tasks. The following build_classpath.xml from a project called com.fedex.build.ant.classpath demonstrates this concept:  To print the classpath for debugging: <!-- Write the classpath to the console. Helpful for debugging --> <!-- Create one line per classpath element--> <pathconvert pathsep="${line.separator}" property="echo.classpath" refid="junit.class.path"> </pathconvert> <!-- Write the result to the console --> <echo message="The following classpath is associated with junit.class.path" /> <echo message="${echo.classpath}" />
  • 7. RUNNING JUNITS VIA ANT  Ant allows to run JUnit tests. Ant defines JUnit task. You only need to include the junit.jar and the compiled classes into the classpath for Ant and then you can run JUnit tests. Below is an example:  You can run this JUnit unit test via the following build_junit.xml. This example assumes that the JUnit jar "junit.jar" is located in “lib” folder. package test; import math.MyMath; import org.junit.Test; import static org.junit.Assert.assertEquals; public class MyMathTest { @Test public void testMulti() { MyMath math = new MyMath(); assertEquals(50, math.multi(5, 10)); } }
  • 8. ANT TIPS  Eclipse has an ant editor which make the editing of ant file very easy by providing syntax checking of the build file. Eclipse has also a ant view. In this view you execute ant files via double-clicking on the target.  Apache Ant allows to convert relative paths to absolute paths i.e. <property name="my.config" value="../my-config.xml"/> <makeurl file="${my.config}" property="my.config.url"/>  Ant can be used to replace text based on regular expressions i.e. <target name="regular-expressions"> <!-- Replace tabs with two spaces --> <replaceregexp flags="gs"> <regexp pattern="(t)" /> <substitution expression=" " /> <fileset dir="${outputtmp.dir}/"> <include name="**/*" /> </fileset> </replaceregexp> </target>