• Save
Apache Ant
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Apache Ant

on

  • 304 views

 

Statistics

Views

Total Views
304
Views on SlideShare
304
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Apache Ant Presentation Transcript

  • 1. Ali Bahu12/24/2012APACHE ANT
  • 2. INTRODUCTION A build tool can be used to automate certain repetitive tasks forexample compiling source code, running software tests andcreating 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 andMaven.
  • 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, atomicsteps, for example compile source code or create Javadoc. Tasks can begrouped into targets. A target can be directly invoked via Ant. Targets can specify theirdependencies. Ant will automatically execute dependent targets. For exampleif target A depends on B, than Ant will first perform B and then A. You canspecify the default target in your build.xml file. Ant will execute this target, ifno 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 FROMECLIPSE 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 switchto your project directory. Type in"ant" or "ant -f build.xml" to startthe build process.
  • 6. APACHE ANT CLASSPATH Ant also allows to create classpath containers and use them intasks. The following build_classpath.xml from a project calledcom.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 toinclude the junit.jar and the compiled classes into the classpath forAnt and then you can run JUnit tests. Below is an example: You can run this JUnit unit test via the following build_junit.xml. Thisexample assumes that the JUnit jar "junit.jar" is located in “lib” folder.package test;import math.MyMath;import org.junit.Test;import staticorg.junit.Assert.assertEquals;public class MyMathTest {@Testpublic 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 byproviding syntax checking of the build file. Eclipse has also a ant view. In thisview 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>