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 (https://fraaargh.wordpress.com/2008/07/13/how-to-java-jars-and-manifestmf):

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

<!– 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” />
</manifestclasspath>

<!– 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”>
<classpath>
<path refid=”class.path” />
</classpath>
</javac>

<!– JAR –>
<jar jarfile=”${SOFT_PACKAGE}/${software.name}” basedir=”${build.dir}”>
<manifest>
<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}”/>
</manifest>

</jar>
</target>

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

  1. daab says:

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

  2. Ton chef says:

    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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s