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>