Presentation is loading. Please wait.

Presentation is loading. Please wait.

95-702 OCT Information Systems Management 1 Lecture 2A Introduction to ANT Written by James Duncan Davidson. Like GNU Make but specifically for Java. Good.

Similar presentations


Presentation on theme: "95-702 OCT Information Systems Management 1 Lecture 2A Introduction to ANT Written by James Duncan Davidson. Like GNU Make but specifically for Java. Good."— Presentation transcript:

1 95-702 OCT Information Systems Management 1 Lecture 2A 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. Built in to Eclipse.

2 95-702 OCT Information Systems Management 2 Ant Concepts 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.

3 95-702 OCT Information Systems Management 3 “Hello World” In Ant ${HelloText} ${HelloOCT}

4 95-702 OCT Information Systems Management 4 Using Ant with Eclipse Create a Workspace and a Project. Right click the project and select new file. Enter text for build.xml. Save. Right click the file and run as Ant build.

5 95-702 OCT Information Systems Management 5 Java Example build.xml <javac srcdir="." destdir="." classpath=".” />

6 95-702 OCT Information Systems Management 6 MyJava.java public class MyJava { public static void main(String a[]) { System.out.println("Hello world"); }

7 95-702 OCT Information Systems Management 7 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

8 95-702 OCT Information Systems Management 8 Another Java Example build.xml examples | --- antdir | | | --- SomeCoolClass.class | --- SomeCoolClass.java --- ant2 | --- build.xml --- MyClass.java The build file needs to compile MyClass.java and needs SomeCoolClass in its classpath.

9 95-702 OCT Information Systems Management 9 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; } }

10 95-702 OCT Information Systems Management 10 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()); }

11 95-702 OCT Information Systems Management 11 build.xml D:\McCarthy\www\95-733\examples\ant2>type build.xml <javac srcdir="." destdir="." >

12 95-702 OCT Information Systems Management 12 build.xml (Continued)

13 95-702 OCT Information Systems Management 13 Ant Execution D:\McCarthy\www\95-733\examples\ant2>ant Buildfile: build.xml compile: run: [java] Hello world x == 3 BUILD SUCCESSFUL Total time: 3 seconds

14 95-702 OCT Information Systems Management 14 Same Example Different build.xml

15 95-702 OCT Information Systems Management 15

16 95-702 OCT Information Systems Management 16 Ant Example from “Ant The Definitive Guide” O’reilly Problem: We have source code in a Java package. We want to create a build directory with class files. We want to place the build directory in a Java archive.

17 95-702 OCT Information Systems Management 17 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

18 95-702 OCT Information Systems Management 18 After ant all D:. │ build.xml │ ├───build │ ├───classes │ │ └───com │ │ └───oreilly │ │ └───sample │ │ Account.class │ │ Person.class │ │ PersonTest.class │ │ └───lib │ orielly.jar

19 95-702 OCT Information Systems Management 19 After ant all (continued) │ └───src └───com └───oreilly └───sample Account.java Person.java PersonTest.java

20 95-702 OCT Information Systems Management 20 build.xml

21 95-702 OCT Information Systems Management 21

22 95-702 OCT Information Systems Management 22 <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." />


Download ppt "95-702 OCT Information Systems Management 1 Lecture 2A Introduction to ANT Written by James Duncan Davidson. Like GNU Make but specifically for Java. Good."

Similar presentations


Ads by Google