Generate manifest class-path from in Ant

<path id="build.classpath">
  <fileset dir="${basedir}">
     <include name="lib/*.jar"/>
  </fileset>
</path>

<pathconvert property="manifest.classpath" pathsep=" ">
  <path refid="build.classpath"/>
  <mapper>
    <chainedmapper>
       <flattenmapper/>
       <globmapper from="*.jar" to="lib/*.jar"/>
    </chainedmapper>
  </mapper>
</pathconvert>

<target depends="compile" name="buildjar">
  <jar jarfile="${basedir}/${test.jar}">
     <fileset dir="${build}" />
     <manifest>
       <attribute name="Main-Class" value="com.mycompany.TestMain"/>
       <attribute name="Class-Path" value="${manifest.classpath}"/>
     </manifest>
 </jar>
</target>

For further information check out this article.

Leave a Comment