Ant Presented by: Mindaugas Idzelis Tatum Krawczyk
Outline What is ant? Why another build tool? How does it work? Tasks (built-in, optional, and third-party) Demo Sample build file Using ant, sample output IDE (Integrated Development Environment) Integration Graphical buildfile editor – Antidote Pros and Cons
What is it? Ant is a Java-based build tool Open Source Portable
Why another build tool? Whats wrong with make? Cryptic syntax Depends on commands found on specific OS Makefiles can execute incorrectly if tab characters are present Only runs in UNIX-like environments Ant Extended using java classes Configuration done using XML Each task is run by an object that implements a particular task interface
How does it work? Hierarchical model A java project will typically have one build file typically named ‘build.xml’ A build file contains a bunch of targets A target is a set of commands that are given a name For example, ‘compile’, ‘document’, or ‘distribute’ Like in make, a target can depend on other targets
How does it work (cont) Targets contain a set of tasks A task is a command that is executed, like compiling, copying files, etc Ant’s tasks are implemented using java classes Tasks can be built in, optional, third-party or custom commands The target that you want to run is specified on the command line If nothing is specified, default target is run Targets are only run once at most
Creating an ant project Create some source files Create a XML build file Create a bunch of targets (i.e. init, build, clean) Fill them in with appropriate commands Run ant on the build file specifying a target if different from default
Examples of tasks Built in tasks Directory tasks Chmod, Delete, Move, Copy, mkdir ChmodDeleteMoveCopymkdir Compression tasks Zip, Gzip, Jar, War, Ear, Tar ZipGzipJarWarEarTar Other tasks Java, Javac, javadoc, style, patch, cvs, signjar, sql, mail, get, parallel, exec, tstamp, touch JavaJavacjavadocstylepatchcvssignjarsql mailgetparallelexectstamptouch
Examples of tasks Optional Tasks Source management Clearcase, perforce, pvcs, continuus/synnergy, MS visual sourcesafe, starteam Testing/profiling Junit, jprobe, metamata metrics Network telnet, ftp, mim Misc.NET, cab, ejb, javacc, netrexx, XmlValidate
Examples of tasks Custom/Third party tasks AspectJ Runs Aspect for Java compiler Anakia xml transformation tool Checkstyle Java source code checker Importscrubber Removes unnecessary import statements from a Java source code file Jalopy Source code formatter J2ME
Sample build file Build.xml
IDE Integration An IDE is basically a text editor designed for source code with a compiler, debugger, and other utilities built in. Java IDE’s that integrate with ant Jbuilder Jext (Java text editor) NetBeans & Forte for Java VisualAge for Java Websphere Studio Application Designer
Graphical Build file editor Antidote Alleviates some of the mistakes that can be made typing ant build file by hand Produces only valid ant build files Prompts you for required attributes, and displays drop down lists for the optional attributes Still in development, only available in source form from the source repository at apache.org
Pros and Cons Ant as a tool Pros Considered the “standard” java make tool Supported by many java vendors including IBM, Borland, Sun Completely written in java, so its portable It is simple to use, powerful, extensible Cons Must be installed in order to be used Build files that depend on optional tasks might not work without additional.jar libraries XML configuration file (required knowledge of XML) Steep learning curve
Criticisms of the XML format it uses Since the ‘depends’ attribute of the element can contain multiple dependencies separated by commas, the text of the attribute must be parsed separately. Also means that it can’t be validated using a DTD Why not make this an id-ref? Will allow xml format to validate references by itself. Response: Making it an id-ref will disallow the possiblity of the following:
Questions
Sources Jakarta ant web site Ant documentation Ant resources Ant presentation to Tucson JUG Ant presentation to St. Louis JUG