Creating a runnable jar. Various problems

I know responding to your question can be frowned upon, but I did manage to solve this problem yesterday. Of all the options I tried I found the fastest solution was to replicate the Eclipse Runnable Jar Export Wizard. It requires the jar-in-jar-loader.zip which can be acquired using the Runnable Jar Export Wizard… or you can find it via Google/Eclipse install.

I found this solution was fast to build (30s) and much faster to run (5s bootup cost). It also left the jar structure very neat with no exploded jars.

<target name="compile" depends="resolve">
    <mkdir dir="bin"/>
    <!-- Copy all non java resources since jar javac will exclude them by default. Needed for xmls, properties etc --->
    <copy todir="bin">
        <fileset dir="src" excludes="**/*.java" />
    </copy>

    <javac srcdir="src" destdir="bin" debug="true" deprecation="on">
        <classpath>
            <path refid="ivy.path" />
        </classpath>
    </javac>
</target>


<!-- Creates the runnable jar. Copies the dependencies as jar files, into the top level of a new jar. 
     This means nothing without a custom classloader and manifest with a jar listing -->
<target name="jar" depends="compile" description="Create one big jarfile.">

    <path id="dependencies.path">
        <fileset dir="lib">
            <include name="**/*.jar" />
        </fileset>
    </path>

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

    <mkdir dir="${dist}"/>
    <jar destfile="${dist}/jar/Runnable.jar" filesetmanifest="mergewithoutmain">
        <manifest>
            <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
            <attribute name="Rsrc-Main-Class" value="mymainclass" />
            <attribute name="Class-Path" value="." />
            <attribute name="Rsrc-Class-Path" value="./ ${manifest.classpath}" />
        </manifest>
        <fileset dir="bin" />
        <zipfileset src="jar-in-jar-loader.zip" />
        <zipfileset dir="lib" includes="**/*.jar*" />
    </jar>
</target>

http://stackoverflow.com/questions/10238330/creating-a-runnable-jar-various-problems