First of all some general recommendation. Any external lib has to be in sight for ant, means on path.
The most primitive approach is to put your ant addons in $ANT_HOME/lib, but that 'pollutes' your ant installation.
Put your external libs in it's own location, f.e. /ant_xtralibs and use the -lib parameter via Ant_ARGS.
The Flaka manual section 2 has some notes about that, more details in the Ant manual.
Your example dealing with antcontrib uses the traditional approach via taskdef resource..
The modern - recommended - way is to use a XML namespace declaration, as the Flaka Manual mentions
right before section 2 :
"Thus all build file snippets shown assume that the build file contains the following XML namespace declaration"
It's also possible to use Flaka via taskdef the traditional way:
<project>
<taskdef resource="it/haefelinger/flaka/antlib.xml">
<classpath>
<pathelement location="/home/rosebud/flaka/ant-flaka-1.02.02.jar"/>
</classpath>
</taskdef>
<!-- when on path via -lib or ANT_ARGS it's enough to use : -->
<taskdef resource="it/haefelinger/flaka/antlib.xml"/>
<logo>
Hello, #{property['ant.file'].tofile.name}
</logo>
</project>
output
Trying to override old definition of datatype filterset
Trying to override old definition of task fail
Trying to override old definition of task echo
[logo] ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
[logo] : Hello, demo.xml :
[logo] ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
note the lines starting with "Trying to override.."
That's because of Flaka extends some ant tasks
but if you put Flaka in it's own namespace :
<project name="demo" xmlns:fl="antlib:it.haefelinger.flaka">
<fl:logo>
Hello, #{property['ant.file'].tofile.name}
</fl:logo>
</project>
output
[fl:logo] ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
[fl:logo] : Hello, demo.xml :
[fl:logo] ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
no more "Trying to override..." means no more collision with ant's own tasks, as Flaka resides in it's own namespace
So to make it short :
1) use ANT_ARGS to bring your extralibs (Flaka .. etc.) in the game
2) use the modern way of Namespace declaration
EDIT after comment asking for namespace combined with classpath EDIT
yes that works, see Ant manual for details about antlib, especially the section
"Load antlib from inside of the buildfile", for Flaka you would use something like :
<project xmlns:fl="antlib:it.haefelinger.flaka">
<taskdef uri="antlib:it.haefelinger.flaka"
resource="it/haefelinger/flaka/antlib.xml"
classpath="path/to/flaka.jar"/>
but i believe you still didn't get the advantages of using $ANT_ARGS
simply use some script to start your ant scripts, f.e. :
for Windows
set JAVA_HOME=C:\java\jdk\1.6.0_26
set ANT_HOME=C:\ant
set ANT_ARGS=-lib C:\ant_xtralibs;C:\ant_testlibs
set PATH=%PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin;C:\cvsnt
:: default
call ant -f %1
:: debug
::call ant -debug -f %1
... etc.
for Linux/Unix - don't forget the quotationmarks on the ANT_ARGS line !
...
ANT_ARGS="-lib /usr/local/ant_xtralibs:/usr/local/ant_testlibs"
export ANT_ARGS
...
You don't need to use taskdef with classpath anymore !!
Using the -lib option to load additional libraries has another benefit.
There are some libs which must be loaded before Ant (f.e. BSF, js, xml)
starts parsing the buildfile.
ANT_ARGS is a special environment variable. Its content is automatically
added to the invocation of Ant.
-- Other possibilities --
1)
put those 'set ANT_ARGS ...' stuff into =
Linux/Unix
$ANT_HOME/bin/ant
Windows
%ANT_HOME%/bin/ant.bat
disadvantage = changes the ant core installation, remember
your changes before you copy your ant installation to
another machine and strange things happen !
2)
put your extralibs in ${user.home}/.ant/lib
advantage = every user may use his own set of libraries
consult the Ant manual for details :
http://ant.apache.org/manual/running.html#commandline
http://ant.apache.org/manual/running.html#libs