Sunday, October 13, 2013

ANT

Apache Ant is a Java based build tool to automate the manual steps used in compiling and deploying a JAVA application

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>


  </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_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
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:-
  1. To match one character we can use ?.java which will include files like A.java, B.java but not AB.java
  2. To match or or more charates we can use  *.java which will includes ny file with extension .java
  3. 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:-
  1. ant.file = The full location of the build file.
  2. ant.version = The version of the Apache Ant installation.
  3. basedir = The basedir of the build, as specified in the basedir attribute of the project element.
  4. ant.java.version = The  version of the JDK that is used by Ant.
  5. ant.project.default-target = The default target of the current project
  6. ant.project.invoked-targets = Comma separated list of the targets that were invoked in the current project
  7. ant.core.lib = The full location of the ant jar file
  8. ant.home = The home directory of Ant installation
  9. 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
  1. FileSet:- It is used to define a collection of files using pattern set or wild cards .
  2. PatternSet :- It is used to create a pattern of files to be used in fileset.
  3. FileList :- It is used to define a collection of files using the explicit names and wild cards can not be used.
  4. FilterSet:-
  5. 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

Features:-
  • It automates the;-
  1. Compilation of code
  2. Packaging of binaries
  3. Deployment to the server
  4. Test the change.
  • It is platform independent.

No comments:

Post a Comment

SpringBoot Application Event Listeners

When a spring boot application starts few events occurs in below order ApplicationStartingEvent ApplicationEnvironmentPreparedEvent Applicat...