Sie sind auf Seite 1von 6

**--INTRODUCTION--**

• Ant uses a build file called build.xml by default for its instructions.
• First statement is : <?xml version = “1.0”?>
• Tags in ant build.xml file - <project>, <target>, <properties>,
<classpath>..<pathelement>
• Top level xml tag is ‘project’ there should only be one project tag in a build file.
• <project name=”test” default=”jar” basedir=”.”>
The default target for the project named test is jar
All activity is relative to the dir specified by basedir
If no basedir is specifiec it defaults to “.” – that is the dir the build file lives in.
• <target> : a project is made up of number of targets that tel ant what it should do,
it consist of series of taks that are specific actions for ant to take.
target attribute – name (required) , depends ( comma separated list of other
targets), description(for –projecthelp), if, unless
• Targets can depend upon each other – target that depends upon each other
demand that the other target get executed first.
<target name=”compile” depends =”compile”> .. </target>
• ‘if’ will be executed on a target only if a given property is defined.
• ‘unless’ will only execute a target if a given property is not defined

**--USEFULL TARGET DEF’N---**


• The first target we will probably specify is ‘init’
o Sets up properties that will be used throughout the build file.
o The advantage of setting variables here is it gives oen place to make
changes that ripple through the entire file.
o Properties can be set directly or by specifying a properties file.

<target name=”init”>
<!--<property name=”name” value=”test”/>-->
<property file =”build.properties”/>
<path id=”classpath”/>
<pathelement path=”${weblogic.jar}”/>
</path>
</target>
• The second target should be ‘prepare’ and it should depend on ‘init’.
o It is used to create any directory structure needed, also copy some needed
files.
o Mkdir creates an entire tree.
<target name =”prepare” depends=”init”>
<mkdir dir=”${build.dir}/META-INF/>
</target>

• Clean useful for enabling clean builds, just delets stuff from previous runs to
ensure that no artifacts persist b/w builds.
• Compile: compile some or all src files from target.
<target name=“compile” depends=“prepare”>
<echo message=“Compiling now…”/>
<javac srcdir=“${src.dir}”
destdir=“${build.dir}
includes=“**/*.java”
classpathref=“classpath”/>
</target>
• ** means any number of dir inside src dir
• Jar creates a jar file

**-- ANT TYPES--**


• Ant has several tags that function like data types
– PatternSet
– FileSet
– DirSet
– Path-Like Structures
• By themselves they are not very useful; they are used to provide information to
various tasks
• A PatternSet is a grouping of patterns that can be used as a filter
– They have an “id” attribute that allows them to be referenced from elsewhere in
the build file, such as from within a FileSet
• They have four attributes
– includes
– includesfile
– excludes
– excludesfile
• Can also be built using nested tags
– <include>
– <exclude>
Eg- <patternset id=”xml.files” includes=”**/*.xml”
excludes=”**/*Test*”/>

<patternset id=”xml.files”>
<include name=”**/*.xml”/>
<exclude name=”**/*Test*”/>
</patternset>
• A fileset represents a grp of files, based on patterns.
• PatternSets can be nested inside a FileSet
• Contains an implicit PatternSet, so it has the same attributes as PatternSet,
plus these
– dir
– defaultincludes, defaultexcludes
– casesensitive
– followsymlinks
• _ The “dir” attribute is required
• Used extensively to decide which files to compile, copy, jar, etc
• DirSets are groups of directories, Works just like FileSet except it selects
directories instead of files Same attributes (except defaultincludes, defaultexcludes),
Can take a nested PatternSet & Like FileSet, DirSet contains an implicit PatternSet.
• Path like structures Represent things that look like paths, i.e.
CLASSPATH, PATH, etc. Ant will convert between : and ; depending on platform.
It Contains location information about directories and jars that are needed for
compiling, etc.
• Have a name and a value
• Once a value is set they cannot be changed – immutable – Changing value
will have no effect (no error & no change)
• Setting a value <property name=“metal" value=“iron“/>
• Referencing a value ${metal} <property name=“metal-db" value=“$
{metal}.db”/>
• Predefined properties
– All system properties (i.e., ${user.home})
– Ant specific properties
<property name=“name” value=“foo”/>
The below is an example to refer to properties file
<property file=”build.properties”/>

**--BUILT IN TASKS--**
• Ant
– calls a target in another build file
– useful to build subprojects
• AntCall
– calls a target in the same build file
• AntStructure
– generates a DTD describing
all known tasks
• Available
– sets a property if a file, class in
CLASSPATH, or system resource
is present
– can test for the property being
set or not set using the
“if” and “unless” attributes
of the target element
• Chmod
– changes permissions of files and
directories (only under UNIX now)
• Copy
– copies files and directories
• Cvs
– executes any CVS command
• Delete
– deletes files and directories
• Echo
– outputs a message to
System.out or a file
• Exec
– executes a system command
• – can restrict use to a specific OS
• ExecOn
– like Exec but files and directories
are passed as arguments
to the system command
• Fail
– exits the build and
optionally prints a message
• Filter
– used by tasks that copy files to
replace all occurrences of an @
delimited string with another string
• FixCRLF
– changes line endings in
a set of files to the convention
of the current OS
• GenKey
– generates a key in a keystore
which is a protected database
of private keys associated
with a digital certificate
• Get
– creates a copy of a remote file
at a specified URL
• can use http and ftp URLs
• GUnzip
– unzips a GZIP file
• GZip
– creates a GZIP file from a file
• Jar
– creates a JAR file
from a set of files
• Java
– runs a Java application
• Javac
– compiles Java source files
• Javadoc/Javadoc2
– generates javadoc HTML files
from Java source files
• Mail
– sends email using SMTP
• Mkdir
– creates a directory and
any missing parent directories
• Move
– moves files and directories
to a new directory
• Patch
– applies a “diff” to file
• Property
– sets properties that can be used in
the current target and other targets
– can load from a property file
• Replace
– replaces all occurrences of a string
with another string in a file
• Rmic
– runs the rmic compiler on
.class files of Java classes that
implement java.rmi.Remote
• SignJar
– uses javasign to add a digital
signature to a jar or zip file
• Sql
– executes a sequence of SQL
statements specified in the
build file or an external text file
– output can be written to a file
• Style
– applies an XSLT stylesheet
to a set of XML files
to produce a set of output files
• Tar
– creates a TAR file
from a set of files
• Taskdef
– defines a custom task
that can be used in the project
• Touch
– creates a file if it doesn’t exist
– updates its modification time
if it does
• Tstamp
– sets the DSTAMP (ccyymmdd),
TSTAMP (hhmm) and
TODAY (month day year)
properties to the current date/time
– useful for creating files and
directories with names that
reflect their creation date/time
• Unjar
– expands a JAR file
• Untar
– expands a TAR file
• Unwar
– expands a WAR file
• Unzip
– expands a ZIP file
• Uptodate
– sets a specified property
if a specified file is newer
than a set of source files
• War
– creates a Web Application Archive
from a set of files in
a directory structure
specified by the Java Servlet spec.
• Zip
– creates a ZIP file
from a set of files

Das könnte Ihnen auch gefallen