ant: another nice tool ali beyad october 1, 2003
TRANSCRIPT
![Page 1: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/1.jpg)
ANT:ANT:Another Nice Another Nice
ToolToolAli BeyadAli Beyad
October 1, 2003October 1, 2003
![Page 2: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/2.jpg)
What is Ant?What is Ant?
Java-based Build tool from ApacheJava-based Build tool from Apache De facto standard for building, De facto standard for building,
packaging, and installing Java packaging, and installing Java applicationsapplications
Accomplishes same objectives that Accomplishes same objectives that makemake does on Unix based systems does on Unix based systems
Files are written in XML Files are written in XML
![Page 3: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/3.jpg)
Why Ant?Why Ant?
Unlike makefiles, Ant files work cross Unlike makefiles, Ant files work cross platformplatform
- No need for multiple, complex makefiles - No need for multiple, complex makefiles depending on the operating depending on the operating system.system.
- Tasks declared in platform independent - Tasks declared in platform independent way; Ant engine translates to OS specific way; Ant engine translates to OS specific commands.commands.
Easy to create own Ant “tasks”, in Easy to create own Ant “tasks”, in addition to core tasksaddition to core tasks
![Page 4: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/4.jpg)
Installing AntInstalling Ant
Download Ant binary distribution Download Ant binary distribution from:from:
http://ant.apache.org/bindownload.cgihttp://ant.apache.org/bindownload.cgi Set ANT_HOME to where you Set ANT_HOME to where you
installed Antinstalled Ant Include $ANT_HOME/bin in PATH Include $ANT_HOME/bin in PATH Make sure JAVA_HOME is set to point Make sure JAVA_HOME is set to point
to JDKto JDK
![Page 5: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/5.jpg)
Running AntRunning Ant
Type Type “ant” “ant” at the command lineat the command line Automatically looks for build.xml file Automatically looks for build.xml file
in current directory to runin current directory to run Type Type “ant –buildfile “ant –buildfile buildfile.xmlbuildfile.xml” ” to to
specify another build file to run.specify another build file to run.
![Page 6: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/6.jpg)
Ant OutputAnt Output
![Page 7: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/7.jpg)
Sample build.xmlSample build.xml<project name="MyProject" default="dist" basedir="."><project name="MyProject" default="dist" basedir="."> <property name="src" location="src"/><property name="src" location="src"/> <property name="build" location="build"/><property name="build" location="build"/> <property name="dist" location="dist"/><property name="dist" location="dist"/>
<target name="init"><target name="init"> <tstamp/><tstamp/> <mkdir dir="${build}"/><mkdir dir="${build}"/> </target></target>
<target name="compile" depends="init" ><target name="compile" depends="init" > <javac srcdir="${src}" destdir="${build}"/><javac srcdir="${src}" destdir="${build}"/> </target></target>
<target name="dist" depends="compile" ><target name="dist" depends="compile" > <mkdir dir="${dist}/lib"/><mkdir dir="${dist}/lib"/> <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/><jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/> </target></target>
<target name="clean" ><target name="clean" > <delete dir="${build}"/><delete dir="${build}"/> <delete dir="${dist}"/><delete dir="${dist}"/> </target></target></project></project>
![Page 8: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/8.jpg)
Ant Overview: ProjectAnt Overview: Project
Each build file contains exactly one Each build file contains exactly one project and at least one targetproject and at least one target
Project tags specify the basic project Project tags specify the basic project attributes and have 3 properties:attributes and have 3 properties:
- name- name
- default target- default target
- basedir- basedir Example: <project name=“MyProject” default=“build” basedir=“.”>Example: <project name=“MyProject” default=“build” basedir=“.”>
![Page 9: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/9.jpg)
Ant Overview: TargetsAnt Overview: Targets
Target is a build module in AntTarget is a build module in Ant Each target contains task(s) for Ant Each target contains task(s) for Ant
to doto do One must be a project defaultOne must be a project default Overall structure of targets:Overall structure of targets:
<target name="A"/> <target name="A"/>
<target name="B" depends="A"/> <target name="B" depends="A"/>
<target name="C" depends="B"/> <target name="C" depends="B"/>
<target name="D" depends="C,B,A"/><target name="D" depends="C,B,A"/>
![Page 10: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/10.jpg)
Ant Overview: TasksAnt Overview: Tasks
Each target comprises one or more Each target comprises one or more taskstasks
Task is a piece of executable Java Task is a piece of executable Java code (e.g. javac, jar, etc)code (e.g. javac, jar, etc)
Tasks do the actual “build” work in Tasks do the actual “build” work in AntAnt
Ant has core (built in) tasks and the Ant has core (built in) tasks and the ability to create own tasksability to create own tasks
![Page 11: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/11.jpg)
Ant Overview: TasksAnt Overview: Tasks
Example:Example: <target name="prepare" depends="init“ ><target name="prepare" depends="init“ >
<mkdir dir="${build}" /><mkdir dir="${build}" /> </target></target>
<target name="build" depends="copy" ><target name="build" depends="copy" >
<javac srcdir="src" destdir="${build}"><javac srcdir="src" destdir="${build}">
<include name="**/*.java" /><include name="**/*.java" />
</javac></javac> </target></target>
![Page 12: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/12.jpg)
Ant Overview: Core TasksAnt Overview: Core Tasks
javac – Runs the Java Compilerjavac – Runs the Java Compiler java – Runs the Java Virtual Machinejava – Runs the Java Virtual Machine jar (and war) – Create JAR filesjar (and war) – Create JAR files mkdir – Makes a directorymkdir – Makes a directory copy – Copies files to specified location copy – Copies files to specified location delete – Deletes specified files delete – Deletes specified files cvs – Invokes CVS commands from Antcvs – Invokes CVS commands from Ant
![Page 13: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/13.jpg)
Ant Overview: Writing Ant Overview: Writing Own TaskOwn Task Create a Java class that extends Create a Java class that extends
org.apache.tools.ant.Taskorg.apache.tools.ant.Task For each attribute, write a setter For each attribute, write a setter
method that is method that is public voidpublic void and takes a and takes a single argumentsingle argument
Write a Write a public void execute()public void execute() method, with method, with no arguments, that throws a no arguments, that throws a BuildException -- this method BuildException -- this method implements the task itselfimplements the task itself
![Page 14: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/14.jpg)
Ant Overview: PropertiesAnt Overview: Properties
Special task for setting up build file Special task for setting up build file properties:properties:
Example:Example:
<property name=“src” value=“/home/src”/><property name=“src” value=“/home/src”/> Can use ${src} anywhere in build file Can use ${src} anywhere in build file
to denote /home/srcto denote /home/src Ant provides access to all system Ant provides access to all system
properties as if defined by the properties as if defined by the <property><property> task task
![Page 15: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/15.jpg)
Ant Overview: Path Ant Overview: Path StructuresStructures Ant provides means to set various Ant provides means to set various
environment variables like PATH environment variables like PATH and CLASSPATH.and CLASSPATH.
Example of setting CLASSPATH:Example of setting CLASSPATH:<classpath> <classpath>
<pathelement path="${classpath}"/> <pathelement path="${classpath}"/>
<pathelement location="lib/helper.jar"/> <pathelement location="lib/helper.jar"/>
</classpath></classpath>
![Page 16: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/16.jpg)
Command Line Command Line ArgumentsArguments -buildfile -buildfile buildfilebuildfile – specify build file to use– specify build file to use targetnametargetname – specify target to run – specify target to run
(instead of running default)(instead of running default) -verbose, -quiet, -debug-verbose, -quiet, -debug – Allows control – Allows control
over the logging information Ant over the logging information Ant outputsoutputs
--logger logger classnameclassname – Allows user to specify – Allows user to specify their own classes for logging Ant eventstheir own classes for logging Ant events
![Page 17: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/17.jpg)
IDE IntegrationIDE Integration
Eclipse, NetBeans, JBuilder, Eclipse, NetBeans, JBuilder, VisualAge, and almost any other Java VisualAge, and almost any other Java IDE has Ant integration built-in to IDE has Ant integration built-in to the systemthe system
Refer to each IDE’s documentation Refer to each IDE’s documentation for how to use Ant with that IDEfor how to use Ant with that IDE
![Page 18: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/18.jpg)
Web Development with Web Development with AntAnt Tomcat comes with special Ant tasks Tomcat comes with special Ant tasks
to ease Web application development to ease Web application development and deploymentand deployment
Copy Copy $TOMCAT_HOME/server/lib/catalina-ant.jar$TOMCAT_HOME/server/lib/catalina-ant.jar to to $ANT_HOME/lib$ANT_HOME/lib
Ant tasks for Tomcat:Ant tasks for Tomcat:- install- install
- reload- reload - deploy- deploy - remove- remove
![Page 19: ANT: Another Nice Tool Ali Beyad October 1, 2003](https://reader035.vdocuments.us/reader035/viewer/2022071705/56649cea5503460f949b5c99/html5/thumbnails/19.jpg)
Documentation/Documentation/ReferencesReferences Download: Download: http://ant.apache.org/bindownload.cgihttp://ant.apache.org/bindownload.cgi
User Manual: User Manual: http://ant.apache.org/manual/index.htmlhttp://ant.apache.org/manual/index.html
Sun’s Web development tutorial (Ant Sun’s Web development tutorial (Ant and JSPs):and JSPs):http://java.sun.com/webservices/docs/1.2/tutorial/doc/GettingStarted3.htmlhttp://java.sun.com/webservices/docs/1.2/tutorial/doc/GettingStarted3.html
Java Development with Ant, by Erik Java Development with Ant, by Erik Hatcher and Steve Loughran Hatcher and Steve Loughran