Download presentation
Presentation is loading. Please wait.
1
1 Introduction to ANT Written by James Duncan Davidson Like GNU Make but specifically for Java Good for bundling and delivery of groups of classes, jars, wars Handles dependencies automatically Written in XML Works on Unix or Windows Available from Apache.org
2
2 Ant programs are XML documents The meaning of the tags is not defined by XML. XML documents can be programs (we’ll see this again with XSLT). The software that reads the Ant documents does two things: -- parses the document (already available to the creator of Ant) -- interprets and executes Ant tasks based on agreed upon semantics
3
3 Some Ant Notes Exactly on project element is required There may be many properties, targets and tasks At least on target is required Targets describe broad goals Tasks are nested within targets Over 100 core tasks available (e.g. mkdir, javac) Properties are name-value pairs Ant interprets the build file with a breadth first traversal across the XML elements under project Inside a target, Ant performs a depth first traversal By default, Ant breaks at the first error
4
4 First Example build.xml <javac srcdir="." destdir="." classpath="." />
5
5 MyJava.java public class MyJava { public static void main(String a[]) { System.out.println("Hello world"); }
6
6 Ant Execution D:\McCarthy\www\95-733\examples\ant2>ant Buildfile: build.xml compile: [javac] Compiling 1 source file to D:\McCarthy\www\95-733 \examples\ant2 run: [java] Hello world BUILD SUCCESSFUL Total time: 17 seconds
7
7 Second Example build.xml examples | --- antdir | | | --- SomeCoolClass.class | --- SomeCoolClass.java --- ant2 | --- build.xml --- MyClass.java
8
8 SomeCoolClass.java D:\McCarthy\www\95-733\examples\antdir> type SomeCoolClass.java public class SomeCoolClass { int x; public SomeCoolClass() { x = 3; } public int getX() { return x; } }
9
9 MyJava.java D:\McCarthy\www\95-733\examples\ant2>type MyJava.java public class MyJava { public static void main(String a[]) { SomeCoolClass p = new SomeCoolClass(); System.out.println("Hello world x == " + p.getX()); }
10
10 build.xml D:\McCarthy\www\95-733\examples\ant2>type build.xml <javac srcdir="." destdir="." >
11
11 build.xml (Continued)
12
12 Ant Exceution D:\McCarthy\www\95-733\examples\ant2>ant Buildfile: build.xml compile: run: [java] Hello world x == 3 BUILD SUCCESSFUL Total time: 3 seconds
13
13 Same Example Different build.xml
14
14
15
15 Ant Example from “Ant The Definitive Guide” O’reilly
16
16 Initial Layout D:\McCarthy\www\95-733\examples\ant>tree /f Directory PATH listing Volume serial number is 0012FC94 486D:D392 D:. │ build.xml │ └─── src └─── com └─── oreilly └─── sample Account.java Person.java PersonTest.java
17
17 After ant all D:. │ build.xml │ ├───build │ ├───classes │ │ └───com │ │ └───oreilly │ │ └───sample │ │ Account.class │ │ Person.class │ │ PersonTest.class │ │ └───lib │ orielly.jar
18
18 After ant all (continued) │ └───src └───com └───oreilly └───sample Account.java Person.java PersonTest.java
19
19 build.xml
20
20
21
21 <target name = "compile" depends = "prepare" description = "Compiles all source code." > <target name = "jar" depends = "compile" description = "Generates oreilly.jar in the 'dist' directory. "> <jar jarfile="${build.lib}/orielly.jar" basedir="${build.classes}" excludes = "**/*PersonTest.class" /> <target name = "all" depends = "clean,jar" description = "Cleans, compiles, then builds the Jar file." />
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.