Lecture 2A Introduction to ANTPowerPoint Presentation“Hello World” In AntUsing Ant with EclipseJava Example build.xmlMyJava.javaAnt ExecutionAnother Java Example build.xmlSomeCoolClass.javaSlide 10build.xmlbuild.xml (Continued)Slide 13Same Example Different build.xmlSlide 15Ant Example from “Ant The Definitive Guide” O’reillyInitial LayoutAfter ant allAfter ant all (continued)Slide 20Slide 21Slide 22195-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.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.295-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.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.395-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.“Hello World” In Ant<?xml version="1.0" encoding="UTF-8"?><project name="Hello OCT" default = "Both" basedir ="."><property name = "HelloText" value="Hello"/><property name = "HelloOCT" value="OCT"/><target name="Hello"><echo>${HelloText}</echo></target><target name = "OCT"> <echo>${HelloOCT}</echo></target><target name ="Both" depends = "Hello,OCT"/></project>495-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.Using Ant with EclipseCreate 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.595-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.Java Example build.xml<?xml version="1.0"?><project basedir="." default="run"> <target name="compile"> <javac srcdir="." destdir="." classpath=".” /> </target> <target name="run" depends="compile"> <java classname="MyJava" /> </target></project>695-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.MyJava.javapublic class MyJava { public static void main(String a[]) { System.out.println("Hello world"); }}795-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.Ant ExecutionD:\McCarthy\www\95-733\examples\ant2>antBuildfile: build.xmlcompile: [javac] Compiling 1 source file to D:\McCarthy\www\95-733 \examples\ant2run: [java] Hello worldBUILD SUCCESSFULTotal time: 17 seconds895-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.Another Java Example build.xmlexamples | --- antdir | | | --- SomeCoolClass.class | --- SomeCoolClass.java --- ant2 | --- build.xml --- MyClass.javaThe build file needs tocompile MyClass.javaand needs SomeCoolClassin its classpath.995-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.SomeCoolClass.javaD:\McCarthy\www\95-733\examples\antdir>type SomeCoolClass.javapublic class SomeCoolClass { int x; public SomeCoolClass() { x = 3; } public int getX() { return x; }}1095-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.MyJava.javaD:\McCarthy\www\95-733\examples\ant2>type MyJava.javapublic class MyJava { public static void main(String a[]) { SomeCoolClass p = new SomeCoolClass(); System.out.println("Hello world x == " + p.getX()); }}1195-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.build.xmlD:\McCarthy\www\95-733\examples\ant2>type build.xml<?xml version="1.0"?><project basedir="." default="run"> <target name="compile"> <javac srcdir="." destdir="." > <classpath> <pathelement path="../antdir/"/> <pathelement path="."/> </classpath> </javac> </target>1295-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.build.xml (Continued) <target name="run" depends="compile"> <java classname="MyJava"> <classpath> <pathelement path="../antdir/"/> <pathelement path="."/> </classpath> </java> </target></project>1395-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.Ant ExecutionD:\McCarthy\www\95-733\examples\ant2>antBuildfile: build.xmlcompile:run: [java] Hello world x == 3BUILD SUCCESSFULTotal time: 3 seconds1495-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.Same Example Different build.xml<?xml version="1.0"?><project basedir="." default="run"> <path id="project.class.path"> <pathelement path="."/> <pathelement path="../antdir/"/> </path> <target name="compile"> <javac srcdir="." destdir="." > <classpath refid="project.class.path"/> </javac> </target>1595-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.<target name="run" depends="compile"> <java classname="MyJava"> <classpath refid="project.class.path"/> </java> </target></project>1695-702 OCT Information Systems ManagementQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.Ant Example from “Ant The Definitive Guide”
View Full Document