title: Generate manifest class-path from <classpath> in Ant
body: <p>In the build file below, the jar target refers to the jar.class.path property for the  manifest class-path. The compile target refers to project.class.path</p>
  
  <p>There is redundancy here, because jar.class.path and project.class.path are very similar. They must be both updated when libraries are added, which can be a pain if the list of libraries gets very long. Is there a better way? Any solution must be cross-platform and always use relative paths.</p>
  
  <p>Edit:<br>
  It should generate the JAR classpath from a fileset and not the other way around, so I can use wildcards to e.g. include all JAR files in a directory.</p>
  
  
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;project name="Higgins" default="jar" basedir="."&gt;
  
      &lt;property name="jar.class.path" value="lib/forms-1.2.0.jar lib/BrowserLauncher.jar"/&gt;
  
      &lt;path id="project.class.path"&gt;
        &lt;pathelement location="build"/&gt;
        &lt;fileset dir="lib"&gt;
          &lt;include name="forms-1.2.0.jar"/&gt;
          &lt;include name="BrowserLauncher.jar"/&gt;
        &lt;/fileset&gt;
      &lt;/path&gt;
  
      &lt;target name="prepare"&gt;
          &lt;mkdir dir="build"/&gt;
      &lt;/target&gt;
  
      &lt;target name="compile" depends="prepare" description="Compile core sources"&gt;
          &lt;javac srcdir="src"
                 includes="**"
                 destdir="build"
                 debug="true"
                 source="1.5"&gt;
            &lt;classpath refid="project.class.path"/&gt;
          &lt;/javac&gt;
      &lt;/target&gt;
  
      &lt;target name="jar" depends="compile" description="Generates executable jar file"&gt;
          &lt;jar jarfile="higgins.jar"&gt;
              &lt;manifest&gt;
                  &lt;attribute name="Main-Class" value="nl.helixsoft.higgins.Main"/&gt;
                  &lt;attribute name="Class-Path" value="${jar.class.path}"/&gt;
              &lt;/manifest&gt;
              &lt;fileset dir="build" includes="**/*.class"/&gt;            
              &lt;fileset dir="src" includes="**/*.properties"/&gt;         
          &lt;/jar&gt;
      &lt;/target&gt;
  
  &lt;/project&gt;
  </code></pre>