Creating Manifest Classpath with Ant
August 29th, 2007
Tags: ant, java
At first, create a fileset (group of files) which describes all the files you want to include in your CLASS-PATH statement.
XML:
-
<fileset id="fileset.lib" dir="${lib}">
-
<include name="*.jar" />
-
</fileset>
Next, convert this fileset into the correct format for the manifest.
XML:
-
<pathconvert property="classpath"
-
refid="fileset.lib"
-
pathsep=" "
-
dirsep="/">
-
<map from="${lib}" to="lib" />
-
</pathconvert
And finally, build the manifest.
XML:
-
<jar jarfile="${dist}/${ant.project.name}.jar" basedir="${build}">
-
<manifest>
-
<attribute name="Class-Path" value="${classpath}"/>
-
</manifest>
-
</jar>







July 11th, 2008 at 4:09 am
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
June 24th, 2009 at 1:07 am
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:
June 24th, 2009 at 1:13 am
I don’t think I posted that code formatted correctly:
#
#
#
#
#
#
#
#
#
#
I tried this and it worked with ant1.7.1
June 24th, 2009 at 1:14 am
<mapper>
<chainedmapper>
<!– remove absolute path –>
<flattenmapper />
<!– add lib/ prefix –>
<globmapper from=”*” to=”lib/*” />
</chainedmapper>
</mapper>