Use ANT to auto-generate the list of jar files in a MANIFEST.MF

Writing a manifest by hand is both error prone & boring. Moreover, if you change the dependancies, add/remove libraries jars from you project, then you have to modify again the manifest file…
One method is to use ANT to create the manifest for you, and more specifically the “Class-Path” line in the manifest.
The following exemple speaks for itself and generate a manifest file as listed in my previous post about jar files (

<path id=”library.Project”>
<fileset dir=”../lib/”>
<include name=”**/*.jar”/>

<!– This is the important line: by specifying in the “jarfile” attribute the location of the
generated jar, ANT will be able to deduce the relative path to you jar libraries –>
<manifestclasspath property=”lib.list” jarfile=”.”>
<classpath refid=”library.Project” />

<!– Compile –>
<target name=”compile” depends=”build.env” description=”Compiles tmmerge Java source code.”>
<mkdir dir=”${build.dir}”/>
<javac srcdir=”${src.dir}” destdir=”${build.dir}” deprecation=”true” debug=”true” optimize=”true”>
<path refid=”class.path” />

<!– JAR –>
<jar jarfile=”${SOFT_PACKAGE}/${}” basedir=”${build.dir}”>
<attribute name=”Class-Path” value=”${lib.list}”/>
<attribute name=”Main-Class” value=”fr.alcatel.ascc.tmmerge.TMMerge”/>
<attribute name=”Product-Name” value=”TMMerge”/>
<attribute name=”Package-Title” value=”fr.alcatel.ascc.tmmerge”/>
<attribute name=”Package-Version” value=”${software.version}”/>



7 thoughts on “Use ANT to auto-generate the list of jar files in a MANIFEST.MF

  1. This was very helpful. The manifestclasspath task, however, is defined in ant 1.7 onwards 😦

  2. Bon, quand t’auras fini de publier des scripts ant, tu pourras enfin finir ce pour quoi on te paie grassement ?

    Enfin, je me comprends.

    Ton chef

    ça va barder

  3. Pingback: faustus eberle

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s