Вы находитесь на странице: 1из 18

Basics of ANT

Puneet SHARMA
Agenda
Introduction What & Why
Installing and Executing ANT
ANT Terminologies and Concepts
Core ANT tasks
Creating a build file
Execute an executable
Executing SQL queries
DEMO
Queries
Introduction
Apache Ant(Ant) is a general purpose build
tool. Ant is an abbreviation forAnother Neat
Tool.
Ant is primarily used for building and
deploying Java projects but can be used for
every possible repetitive tasks.
ANT is Operating System and Language
Neutral.
ANT is implemented in Java.
What ANT can do ?
Ant can get source code from version control
CVS, Subversion, Synergy, Perforce, ClearCase
and many more
Ant can compile source code
Ant can run unit tests
JUnit3, JUnit4, TestNG, or any arbitrary test
application
Ant can package compiled code and resources
jars, wars, ears, tars, zips, whatever
Installing ANT
Download latest stable zip file
fromhttp://ant.apache.org/bindownload.cgi
Unzip downloaded file into a directory
Setup Environment Variables
DefineANT_HOMEto be the location where Ant was
unzipped
DefineJAVA_HOMEto be the location where the JDK
is installed
Add%ANT_HOME%\binto thePATH
Check your installation by opening a command line
and typingant -versioninto the commend line.
ANT Terminologies
Ant Project a collection of named targets that
can run in any order. Each build file contains one
project.
Ant Target a fixed series of ant tasks in a
specified order that can depend on other named
targets. Targets can depend only on other targets,
not on projects or tasks. A target represents a
particular item to be created, it can be a single
item like a jar, or a group of items, like classes.
Ant Task something that ant can execute such as
a compile, copy or replace. Most tasks have very
convenient default values.
ANT Project
Each build file should contains one project which contains
the targets and the tasks to perform.
Aprojecthas three attributes:

Attribute Description Required


name The name of the project. No
default The default target to use when no target is supplied. No
basedir The base directory from which all path calculations are done. No

Each project defines one or moretargets. A target is a set


oftasksyou want to be executed. When starting Ant, you
can select which target(s) you want to have executed.
When no target is given, the project's default is used.
ANT - Targets
A target is a container of tasks that cooperate
to reach a desired state during the build
process.
Targets can depend on other targets and
Apache Ant ensures that these other targets
have been executed before the current
target.
Attribute Description Required

A target
name
has the following attributes:
The name of the target. Yes

depends A comma-separated list of names of targets on No


which this target depends.
if The name of the property that must be set in No
order for this target to execute.
unless The name of the property that must not be set in No
order for this target to execute.
description A short description of this target's function. No
ANT - Tasks
A task is a piece of code that can be executed.
We have inbuilt tasks available for all the basic functions
needed for the build creation and automation.
File Tasks:
<copy>, <concat>, <delete>, <filter>, <fixcrlf>, <get>
Compile Tasks:
<javac>, <apt>,<rmic>
Archive Tasks:
<zip>,<unzip>,<war>,<unwar>,<ear>
Testing Tasks:
<junit>,<junitreport>
Miscelleneous Tasks:
<echo>,<javadoc>,<sql>
ANT Tasks
Apply/Exec
Ant AntCall ANTLR AntStructure AntVersion On Apt Attrib Augment Avail
Continuus/Synergy CvsChangeL
Basename Bindtargets BuildNumber BUnzip2 BZip2 Cab Tasks og Checksum Chg
Clearcase Supported
Chmod Chown Tasks Componentdef Concat Condition conditions Copy Copydir Copy
Cvs CVSPass CvsTagDif CvsVersion Defaultexcludes Delete Deltree Depend Dependset Diagn
Dirname Ear Echo Echoproperties EchoXML EJB Tasks Exec Fail Filter FixC
FTP GenKey Get GUnzip GZip Hostinfo Image Import Include Inp
Jarlib-
Jar available Jarlib-display Jarlib-manifest Jarlib-resolve Java Javac JavaCC Javadoc/Javadoc2 Jav
LoadPro
JDepend JJDoc JJTree Jlink JspC JUnit JUnitReport Length LoadFile s
LoadResourc
e Local MacroDef Mail MakeURL Manifest ManifestClassPath MimeMail Mkdir Mo
PathConver PropertyFile
Native2Ascii NetRexxC Nice Parallel Patch t PreSetDef ProjectHelper Prop
PropertyHelp ResourceCou
er Pvcs Record Rename RenameExtensions Replace ReplaceRegExp nt Retry REx
SchemaValid ServerDeplo
Rmic Rpm ate Scp Script Scriptdef Sequential y Setproxy Sign
SourceOfSit
Sleep e Sound Splash Sql Sshexec Sshsession Subant Symlink Sy
Tar Taskdef Telnet Tempfile Touch Translate Truncate TStamp Typedef Un
Microsoft
Visual
Untar SourceSafe Weblog
Unwar Unzip Uptodate VerifyJar Tasks Waitfor War WhichResource Com
XmlProperty
XmlValidate XSLT/Style Zip
Creating a Build File
Build File is an XML file which contains all the
configuration which is executed by ANT to
create build and performing other Tasks.
The Sample Build file to create a build is
attached below:
build.xml
Executing Executables
EXEC is an inbuilt task in Ant which helps us to
run any executable through ANT.
Sample Execution of MQL
<target name="exec-mql">
<exec executable="mql -c">
<arg value="set context user
creator;compile prog * force update;"/>
</exec>
</target>
Executing SQL queries
Sometimes executing SQL queries also is a part of
application build. In that case ANT can help you to
automate the SQL execution as a part of ANT build.
Connecting to Database:
<sql
driver="org.database.jdbcDriver
url="jdbc:database-url
userid="sa
password="pass
src="data.sql
/>
Here src conatins the sql script to be executed.
Executing SQL queries
Executing Query:
<sql
driver="org.database.jdbcDriver
url="jdbc:database-url
userid="sa
password="pass>
truncate table some_other_table;
</sql>
Executing SQL transactions
Executing Query:
<sql
driver="org.database.jdbcDriver
url="jdbc:database-url
userid="sa
password="pass >
<transaction src="data1.sql"/>
<transaction src="data2.sql"/>
<transaction src="data3.sql"/>
<transaction>
truncate table some_other_table; </transaction>
</sql>
DEMO

DEMO.zip
Questions
ANT

Puneet Sharma.

Вам также может понравиться