It involves a build file that should be inside the project directory. This build file must have
- A project element
- At least one target element
<?xml version="1.0"?>
<project name="PROJECT_NAME" default="info" basedir="BASE_DIRECTORY">
<property name="PROPERTY_NAME" value="PROPERTY_VALUE" />
<property file="PROPERTY_FILE_NAME"/>
<patternset id="PATTERN_SET_ID">
<include name="PATTERN_OF_FILES_TO_BE_INCLUDED"/>
<exclude name="PATTERN_OF_FILES_TO_BE_EXCLUDED"/>
</patternset>
<filelist id="FILELIST_ID" dir="DIRECTORY_OF_FILES">
<file name="FILE_l"/>
<file name="FILE_2"/>
</filelist>
<target name="TARGET_NAME" depends="TARGET_1, TARGET_2, TARGET_3,.." description="TARGET_DESCRIPTION" if="IF_CONDITION" unless="UNLESS_CONDITION">
<echo>Hello World - Welcome to Apache Ant! $(PROPERTY_NAME)</echo>
<delete>
<fileset dir="${PROPERTY_NAME}" casesensitive="YES_NO">
<include name="PATTERN_OF_FILES_TO_BE_INCLUDED"/>
<exclude name="PATTERN_OF_FILES_TO_BE_EXCLUDED"/>
</fileset>
</delete>
<delete>
<fileset dir="DIRECTORY_OF_FILES" casesensitive="yes">
<patternset refid="PATTERN_SET_ID"/>
</fileset>
</delete>
</target>
<target name="TARGET_NAME">
<zip destfile="DESTINATION_FILE_NAME" >
<filelist refid="FILELIST_ID" />
</zip>
</target>
<target name="TARGET_NAME">
<copy todir="DESTINATION_DIRECTORY">
<fileset dir="SOURCE_DIRECTORY" includes="FILTER_PATTERN"></fileset>
<filterset>
<filter token="TOKEN" value="REQUIRED_VALUE_OF_TOKEN"></filter>
</filterset>
</copy>
</target>
<target name="TARGET_NAME">
<zip destfile="DESTINATION_FILE_NAME" >
<filelist refid="FILELIST_ID" />
</zip>
</target>
<target name="TARGET_NAME">
<copy todir="DESTINATION_DIRECTORY">
<fileset dir="SOURCE_DIRECTORY" includes="FILTER_PATTERN"></fileset>
<filterset>
<filter token="TOKEN" value="REQUIRED_VALUE_OF_TOKEN"></filter>
</filterset>
</copy>
</target>
</project>
PROJECT_NAME:- is optional and is the name of the project.
PROPERTY_NAME: is optional and is used to set the name for a variable/property.
PROPERTY_VALUE: is optional and is used to set the value for a variable/property.
PROPERTY_VALUE: is optional and is used to set the value for a variable/property.
PROPERTY_FILE_NAME: is optional and is used to set the name for properties file.
DEFAULT:- is mandatory and is used to set the default target
BASE_DIRECTORY:- is optional and used to set the base directory for the project.
TARGET_NAME: is madatory and used to set the name of the target.
TARGET_1, TARGET_2, TARGET_3,..; are optional and are comma separated list of targets on which the TARGET_NAME depends.
TARGET_DESCRIPTION:- is optional and is used to describe a target
TARGET_1, TARGET_2, TARGET_3,..; are optional and are comma separated list of targets on which the TARGET_NAME depends.
TARGET_DESCRIPTION:- is optional and is used to describe a target
DIRECTORY_OF_FILES:-It is used to set the directory where the filelist or fileset is to be generated.
PATTERN_OF_FILES_TO_BE_INCLUDED:- It is used to set the pattern of the files to be included in the datatype.
PATTERN_OF_FILES_TO_BE_EXCLUDED:- It is used to set the pattern of the files to be exceluded in the datatype.PATTERNS can be set as:-
- To match one character we can use ?.java which will include files like A.java, B.java but not AB.java
- To match or or more charates we can use *.java which will includes ny file with extension .java
- To match zero or more directories recursively we can use **
PATTERN_SET_ID:- It can be used to provide a name to a pattern set so that it may be used again and again in build file.
FILELIST_ID:- It can be used to provide a name to a file list so that it may be used again and again in build file.
TOKEN:- It can be string in the file that is surrounded by separators @ e.g. @VERSION@. It is replaced by the value as given in the attribute value of the filter tag.
Predefined properties in ANT:-
- ant.file = The full location of the build file.
- ant.version = The version of the Apache Ant installation.
- basedir = The basedir of the build, as specified in the basedir attribute of the project element.
- ant.java.version = The version of the JDK that is used by Ant.
- ant.project.default-target = The default target of the current project
- ant.project.invoked-targets = Comma separated list of the targets that were invoked in the current project
- ant.core.lib = The full location of the ant jar file
- ant.home = The home directory of Ant installation
- ant.library.dir = The home directory for Ant library files - typically ANT_HOME/lib folder.
Data Types in ANT:- Data types here mean the services that are provided by ANT by default
- FileSet:- It is used to define a collection of files using pattern set or wild cards .
- PatternSet :- It is used to create a pattern of files to be used in fileset.
- FileList :- It is used to define a collection of files using the explicit names and wild cards can not be used.
- FilterSet:-
- Path
Note:- Pattern set can be used inside fileset but filelist can not be.
To run a target go to the location of build file in command prompt and type
ant TARGET_NAME
- It automates the;-
- Compilation of code
- Packaging of binaries
- Deployment to the server
- Test the change.
- It is platform independent.
No comments:
Post a Comment