Ant - Classpath


Classpath in a Ant Context


The classpath element is defined in and have the scope of a task.

    <pathelement location="lib/helper.jar"/>
    <pathelement path="${classpath}"/>


  • the location attribute refer to a single file or directory relative to the project's base directory (or an absolute filename)
  • the path attribute accepts colon- or semicolon-separated lists of locations. <note tip>PATH attribute use also “:” and “;” as separator characters.</note>


Libraries can be added to Ant's classpath in any of the following way:

Priority Library Library Scope
1 in ANT_HOME/lib directory All Ant users and builds
2 in ${user.home}/.ant/lib (as of Ant 1.6) The command-line Ant
3 with the command line -lib parameter The command
4 in the CLASSPATH environment variable <note warning>To Avoid</note> All Java applications
5 in the <classpath> element <note tip>Preferred option</note> The task



To test for classpath-related problems, set the -noclasspath option. Ant will then stop using the CLASSPATH environment variable.

ant -noclasspath 

Documentation / Reference

Powered by ComboStrap