Tags: ,

At first, create a fileset (group of files) which describes all the files you want to include in your CLASS-PATH statement.

XML:
  1. <fileset id="fileset.lib" dir="${lib}">
  2.   <include name="*.jar" />
  3. </fileset>

Next, convert this fileset into the correct format for the manifest.

XML:
  1. <pathconvert property="classpath"
  2.          refid="fileset.lib"
  3.          pathsep=" "
  4.          dirsep="/">
  5.       <map from="${lib}" to="lib" />
  6. </pathconvert

And finally, build the manifest.

XML:
  1. <jar jarfile="${dist}/${ant.project.name}.jar" basedir="${build}">
  2.     <manifest>
  3.     <attribute name="Class-Path" value="${classpath}"/>
  4.     </manifest>
  5. </jar>

4 Responses to “Creating Manifest Classpath with Ant”

  1. stompnoise Says:

    This method generates an absolute classpath based on the builders pc which makes the jar file not portable. Is the a way to generate a relative classpath? manifest entry should be like Class-Path: /lib/something.jar /lib… tnx

  2. derek Says:

    As to stompnoise’s question I was wondering the same thing. I found this site that explains how to do that:

    http://martin.ankerl.com/2005/11/30/howto-create-manifestmf-classpath-from-ant/

    Basically you just add the following between your path convert tags:

  3. derek Says:

    I don’t think I posted that code formatted correctly:

    #
    #
    #
    #
    #
    #
    #
    #
    #
    #

    I tried this and it worked with ant1.7.1

  4. derek Says:

    <mapper>
    <chainedmapper>

    <!– remove absolute path –>
    <flattenmapper />

    <!– add lib/ prefix –>
    <globmapper from=”*” to=”lib/*” />
    </chainedmapper>
    </mapper>

Leave a Reply