
As mentioned before, Eclipse allows you to add Classpath Libraries to your classpath. A Classpath Library is a set of files and directories that gets added to the classpath. There are two kind of libraries:
A classpath entry for a Classpath Library has set its kind attribute to con ("Container"). Its path attribute consists of the library type (a "User Library" for example is of type "org.eclipse.jdt.USER_LIBRARY") and it's name (last part of the path). If you use the JUnit library for JUnit4, in your project the classpath entry for this library would look like this:
<classpath> ... <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> </classpath>
jdtClasspathLibrary Ant type, that takes a set of resources that will be added to your classpath wherever you reference the library.jdtClasspathLibraryThe jdtClasspathLibrary allows you to define a classpath library. The type expects the name of the library (that is the whole path attribute of the classpath entry). To define the resources, that you want to add to your classpath whereever you use the library, use one or more resource collections. Please see Resource Collections in the Ant documentation for more informations on resource collections.
The following example declares the JUnit4 library with all jar-files that are located beneath c:\libs\junit4:
<ant4eclipse:jdtClassPathLibrary name="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"> <!-- Define that resources that should be added to the classpath. Note that you can specify more than one resource collection element --> <fileset dir="c:/libs/junit4" includes="**/*.jar"/> </ant4eclipse:jdtClasspathLibrary>

Eclipse allows you to export (and import) your User Library definitions to an XML file. Ant4Eclipse is able to read this file and setup up the User Libraries for your build acordingly. In Eclipse you can export the library definitions via the User Libraries preference page (Preferences -> Java -> Build path -> User libraries -> Export...). The exported file can be read by the userLibraries Ant type. The usage of this type is straightforward, simply pass in the path to your exported file. If you have exported your libraries to "c:\ant4eclipse\all.userlibraries" you would use the userLibraries type this way:
<ant4eclipse:userLibraries userLibraries="c:/ant4eclipse/all.userlibraries"/>While it's quite handy to use Classpath Libraries in Eclipse, it has some drawbacks when you implement a build, that propably run (automatically) outside of Eclipse: