View RSS Feed

My Java Tips

Ant Paths

Rate this Entry
by , 11-21-2011 at 05:05 PM (748 Views)
If you specify the PATH and the CLASSPATH type references using any of this, that is ":" and ";" as a separator characters, Ant can convert the separator to the correct character of the operating system in the use.

A nested element can be used wherever path like values need to be specified. See the example below.
Java Code:
<pathelement path="${classpath}"></pathelement>
<pathelement location="lib/helper.jar"></pathelement>
The path attribute is intended to be used with predefined paths. The path attribute accepts colon or semicolon separated lists of locations. In any other case, several other elements with location attributes should be preferred.

As a shortcut, the <classpath> tag supports path and location attributes of its own, so:</classpath>
Java Code:
<pathelement path="${classpath}"></pathelement>
can be shortened to:
Java Code:
    <classpath path="${classpath}">
Further, one or more Resource Collections can be specified as a nested elements. These must consist of file-type resources only. Certain resource collection types such as fileset, dirset and files are undefined in terms of order.

Java Code:
<pathelement path="${classpath}"></pathelement>
      <fileset dir="lib">
        <include name="**/*.jar"></include>
<pathelement location="classes"></pathelement>
      <dirset dir="${build.dir}">
        <include name="apps/**/classes"></include>
        <exclude name="apps/**/*Test*">
      <filelist refid="third-party_jars">
This builds a path that has the value of ${classpath}, followed by all jar files in the lib directory, the classes directory, all directories named classes under the apps subdirectory of ${build.dir}, except those that have the text Test in their name, and the files specified in the referenced FileList.

If you want to use the same path-like structure for mutiple tasks, you can define them with a
<path> element at the same level as targets, and reference them via their id attribute.</path></p>
Follow the next post on this topic.

Submit "Ant Paths" to Facebook Submit "Ant Paths" to Digg Submit "Ant Paths" to Submit "Ant Paths" to StumbleUpon Submit "Ant Paths" to Google