ant task to remove files from a jar

Have you tried using the zipfileset task?

<jar destfile="stripped.jar">
    <zipfileset src="full.jar" excludes="files/to/exclude/**/*.file"/>
</jar>

For example:

<property name="library.dir" value="dist"/>
<property name="library.file" value="YourJavaArchive.jar"/>
<property name="library.path" value="${library.dir}/${library.file}" />
<property name="library.path.new" value="${library.dir}/new-${library.file}"/>

<target name="purge-superfluous">
    <echo>Removing superfluous files from Java archive.</echo>

    <jar destfile="${library.path.new}">
        <zipfileset src="${library.path}" excludes="**/ComicSans.ttf"/>
    </jar>

    <delete file="${library.path}" />
    <move file="${library.path.new}" tofile="${library.path}" />
</target>

If a jar-file capable archiver program, like e.g. "zip" on Linux, is available, the task can be done by

<exec executable="zip">            
<arg value="-d"/>            
<arg value="myJarCopyToStrip.jar"/>            
<arg value="aaa/bbb/def/*>            
<arg value="aaa/bbb/def>
</exec>

Subtree deletion depends on the capabilities of the used archiver.
The "os" attribute of the Ant "exec" task allows to use different archivers on different OS's.


You have to unjar and rejar.

<unzip src="myjar.jar" dest="/classes/">
<jar destfile="newjar.jar"
    basedir="/classes/"
    includes="**/*"
    excludes="**/def/*"
/>    

The answers didn't quite add up for me -

<zip destfile="tmp.jar">
        <zipfileset src="src.jar">
                <exclude name="**/*.class" />
        </zipfileset>
</zip>
<move file="tmp.jar" tofile="src.jar" /> 

This uses a single pass and doesn't add too much time to the build

source : http://ant.1045680.n5.nabble.com/Remove-entru-from-ZIP-file-using-ANT-td1353728.html