Get Ant into your bloodstream
Lately it seems that my friend the ant, otherwise known as the excellent build tool Ant, and I were meant for each other. Mountains and valleys mean nothing to an ant. It gets across them all. If working with Ant has become your daily bread and writing your own tasks is no longer a challenge, Ant-contrib will come in handy.
Ant-contrib is a collection of useful tasks that turn Ant into a full-fledged scripting language. You can use Ant without this extension, but it is much harder. These are the tasks I find most useful.
Foreach, For — Iterate over a list, such as a property containing paths, and call the appropriate target for each item.
If — A conditional with else and else if. Compare variables or constants, although the comparison is limited to equality.
Variable — Change the value of a variable.
Switch — A standard switch.
Trycatch — The familiar try, catch and finally.
Examples
<if> <equals arg1="${foo}" arg2="bar" /> <then> <echo message="The value of property foo is bar" /> </then> <else> <echo message="The value of property foo is not bar" /> </else> </if><echo message=“The first five letters of the alphabet are:”/> <for list=“a,b,c,d,e” param=“letter”> <sequential> <echo>Letter @{letter}</echo> </sequential> </for>
<trycatch property=“foo” reference=“bar”> <try> <fail>Tada!</fail> </try>
<catch> <echo>In <catch>.</echo> </catch>
<finally> <echo>In <finally>.</echo> </finally> </trycatch>
<var name=“x” value=“6”/> <if> <equals arg1=”${x}” arg2=“6” /> <then> <var name=“x” value=“12”/> </then> </if> <echo>${x}</echo> <!— will print 12 —>
Medium version · Archived original page
Related articles
Related CZ Podcast episodes
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio