Ant task to remove signature from jar file

This article suggest an Ant macro that removes the publisher signature from an java .jar file, also known as to ‘unsign’ a jar.

    <macrodef name="unsignjar">
        <attribute name="jarFile" />
        <sequential>
            <jar update="yes"
                 jarfile="@{jarFile}.tmp">
                <zipfileset src="@{jarFile}">
                    <include name="**"/>
                    <exclude name="META-INF/*.SF"/>
                    <exclude name="META-INF/*.DSA"/>
                    <exclude name="META-INF/*.RSA"/>
                </zipfileset>
            </jar>
            <move file="@{jarFile}.tmp" 
                  tofile="@{jarFile}"
                  overwrite="true" />
        </sequential>
    </macrodef>

An example how to call the macro.

    <target ...>
        ...
        <unsignjar jarFile="hibernate.jar" />
        ...
    </target>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: