Creating a bundle jar with ant

In my target, I have something like this:

<jar destfile="https://stackoverflow.com/questions/1821803/${store.dir}/temp_final.jar" filesetmanifest="skip">
    <zipgroupfileset dir="dist" includes="*.jar"/>
    <zipgroupfileset dir="dist/lib" includes="*.jar" excludes=""/>

    <manifest>
        <attribute name="Main-Class" value="${main.class}"/>
        <attribute name="Class-Path" value="${mf.classpath}"/>
    </manifest>
</jar>

And here is how I build my classpath:

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

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

mf.classpath is used from the package target posted above.
This part I copied from somewhere else, so I’m not all that familiar with it.

Quick edit.
Javac needs to know about those jars too.

<path id="https://stackoverflow.com/questions/1821803/jars">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>

<target name="compile">
    <mkdir dir="${build.dir}"/>
    <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="https://stackoverflow.com/questions/1821803/jars" debug="on"/>
</target>

Leave a Comment