Upload
barbara-francis
View
213
Download
0
Embed Size (px)
Citation preview
Introduction to Introduction to antant
Guy Rixon
AstroGrid Consortium Meeting
2002-01-12
AstroGrid consortium meeting, January 2003 Introduction to ant, slide 2
What is What is antant??
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. http://jakarta.apache.org/ant/
AstroGrid consortium meeting, January 2003 Introduction to ant, slide 3
Why Why antant instead of instead of makemake??
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 2003 Introduction to ant, slide 4
Pieces to run Pieces to run antant
Ant packageBuild file, usually build.xml*.properties filesPackage to be built and/or run.JDK
AstroGrid consortium meeting, January 2003 Introduction to ant, slide 5
Ant installationAnt installation
Ant is not preinstalled with the OS. Get it from www.apache.org
– 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 2003 Introduction to ant, slide 6
Build file for Build file for antant
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 2003 Introduction to ant, slide 7
Inside a build fileInside a build file
<project name=“HelloWorld” default=“compile”> <property file=“build.properties”/> <target name=“compile”> <javac srcdir=“.”> </target>
<target name=“install”> <chmod file=“HelloWorld.class” perm=“g-w”/> <copy file=“HelloWorld.class”
todir=“${install.dir}/lib”/> </target> </project>
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 2003 Introduction to ant, slide 8
Properties filesProperties 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 2003 Introduction to ant, slide 9
Running antRunning 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 2003 Introduction to ant, slide 10
Some other ant tasksSome 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 2003 Introduction to ant, slide 11
But does it But does it reallyreally work? 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 1.5.0 1.5.1
Docs are neither complete nor completely accurate.
…but overall it works rather well.
AstroGrid consortium meeting, January 2003 Introduction to ant, slide 12
Further examplesFurther 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 (www.globus.org/ogsa/)
– Subroutines;– Calls between build files;– Loadsa properties;– Ant calls to run built applications;– Probably as antsy as anybody needs to get.