Introduction to ant Guy Rixon AstroGrid Consortium Meeting
AstroGrid consortium meeting, January 2003Introduction to ant, slide 2 What is ant? A software-building utility. A replacement for make. A utility for running Java classes. A product of the Jakarta project at the Apache Foundation. Pervasive in O/S Java stuff Chosen for AstroGrid development.
AstroGrid consortium meeting, January 2003Introduction to ant, slide 3 Why ant instead of make? Cleaner syntax – Based on XML – Verbose but explicit Greater power, e.g. – Recursive operation on directory trees – Customization/localization using properties files – Links for CVS. Portable – Works on any Java-enabled machine – works on Windows
AstroGrid consortium meeting, January 2003Introduction to ant, slide 4 Pieces to run ant Ant package Build file, usually build.xml *.properties files Package to be built and/or run. JDK
AstroGrid consortium meeting, January 2003Introduction to ant, slide 5 Ant installation Ant is not preinstalled with the OS. Get it from – Look in the “Jakarta” pages – Binary distribution is fine, no need to build from source – V1.5.1 preferred; vv1.4.x are obsolete. Install by untarring/unzipping into $ANT_HOME Put $ANT_HOME/bin on your PATH. Put $ANT_HOME/lib/*.jar on your CLASSPATH.
AstroGrid consortium meeting, January 2003Introduction to ant, slide 6 Build file for ant Ant equivalent of makefile: – file of build instructions – specific to one s/w package. XML, using a vocabulary specific to ant. Ant expects build.xml by default. – Can use build files with other names. One build file can call another. Expect to write at least one build file for each s/w package you produce.
AstroGrid consortium meeting, January 2003Introduction to ant, slide 7 Inside a build file <chmod file=“HelloWorld.class” perm=“g-w”/> <copy file=“HelloWorld.class” todir=“${install.dir}/lib”/> Top-level element of document; exactly one of these Like a makefile target “task”: individual command Multiple, independent targets Read settings from config file Tasks in the same target are sequential Use value set elsewhere; c.f. macros in makefiles
AstroGrid consortium meeting, January 2003Introduction to ant, slide 8 Properties files Set named properties for use in build files. Contain name-value pairs, e.g.. install.dir=/usr/local build.properties for customizing builds – Written/tweaked by installer, not s/w author – Saves hacking the actual build-file – Name seems to be a common convention (but have to load it explicitly; no default loading) – Can have properties files with other names.
AstroGrid consortium meeting, January 2003Introduction to ant, slide 9 Running ant Build commands look like this: ant compile where the argument is the name of the target in the build file. Set properties like this: ant –Dinstall.dir=/usr/local leaving no space after the –D.
AstroGrid consortium meeting, January 2003Introduction to ant, slide 10 Some other ant tasks cvs – work with CVS repository gzip, gunzip – use compression junit – run unit tests jar, tar – use archive files sql – use database via JDBC exec – run any external command …and about 3 dozen others. You can write your own ant tasks.
AstroGrid consortium meeting, January 2003Introduction to ant, slide 11 But does it really work? make has features; ant has actual bugs. E.g.: – Java tasks fail unless forked into separate JVM – Sometimes fails to find the Java compiler. Ant is still evolving; functions not all stable, e.g.: – delete task changes behaviour Docs are neither complete nor completely accurate. …but overall it works rather well.
AstroGrid consortium meeting, January 2003Introduction to ant, slide 12 Further examples ag-ogsa-echo in AstroGrid CVS. – Minimalist approach ACE ag-ogsa-service-template in AstroGrid CVS – Reusable build-file via lots of properties. OGSA tech-preview ( – Subroutines; – Calls between build files; – Loadsa properties; – Ant calls to run built applications; – Probably as antsy as anybody needs to get.