This task's purpose is to free Ant users from explicitly specifying full path names of libraries they use when compiling projects.
Ordinarily, in order to add a library to classpath one needs to refer to it as shown in the following example:
<target name="compile" depends="init"> <javac srcdir="src" destdir="classes" classpath="d:/share/java/struts-1.0/struts.jar" /> </target>
In larger projects (or simply to keep your tiny project tidy) you could name libraries indirectly, using property task to declare more abstract names for them:
<target name="init"> <property name="struts.jar" value="d:/share/java/struts-1.0/struts.jar" /> </target> <target name="compile" depends="init"> <javac srcdir="src" destdir="classes" classpath="${struts.jar}" /> </target>
This makes it simpler to replace libraries with newer versions while not needing to update build.xml file in many places.
Whichever way you choose, you are still bound to specifying actual path to the library file. This poses little problem when you have copies of libraries in your project's local directory, eg. lib. However, not all project deserve getting their own copies of all the libraries they use, especially, when they are just small projects carrying only a few files.
This is when the Resolver task comes in handy. Most developers tend to keep libraries and other utilities in more or less organized way, usually in a directory like /usr/local/share or ~/lib. Why make unnecessary copies or type lengthy directory names when you can simply name the library you want to use without worrying about its location on your hard drive?
Imagine that you could rewrite the above build.xml file fragment to read:
<target name="init"> <lib name="struts.jar" library="jakarta.struts" version="newest" /> <!-- now the ${struts.jar} variable holds value of "d:/share/java/struts-1.0/struts.jar" --> </target> <target name="compile" depends="init"> <javac srcdir="src" destdir="classes" classpath="${struts.jar}" /> </target>
The lib task introduced above works just like property task except that it translates its library argument to the library's full path according to a system-wide library registry.
In order to use the lib task you should declare it in your build.xml file with <taskdef>:
<project name="test" basedir="." default="all"> <taskdef name="lib" classname="pl.jazzpolice.ant.taskdefs.library.LibraryTask" /> ...
Of course, the LibraryTask class still must be found by Ant, and unfortunately we cannot refer to it with the abbreviated syntax which lib task uses ;-) It would be best to drop resolver.jar file to ANT_HOME/lib directory where ANT_HOME is Ant's installation directory. Otherwise you could use classpath attribute with <taskdef> task.
The registry mentioned above consists of one xml file which describes how short library names should be translated to full pathnames. This file should be named ANT_HOME/library.xml. A sample library.xml file is provided in the release tarball (both source and binary) in doc subdirectory.
You can contact the author at lkowalczyk@users.sourceforge.net.
It may be accessed on the project download page.