Skip to content

Instantly share code, notes, and snippets.

@jarek-przygodzki
Created February 18, 2013 21:48
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarek-przygodzki/4981074 to your computer and use it in GitHub Desktop.
Save jarek-przygodzki/4981074 to your computer and use it in GitHub Desktop.
Unsign a JAR with Ant
<!-- http://frank.zinepal.com/unsign-a-jar-with-ant -->
<macrodef name="unsignjar">
<attribute name="jar"/>
<sequential>
<!-- Remove any existing signatures from a JAR file. -->
<tempfile prefix="usignjar-" destdir="${java.io.tmpdir}" property="temp.file"/>
<echo message="Removing signatures from JAR: @{jar}"/>
<mkdir dir="${temp.file}"/>
<unjar src="@{jar}" dest="${temp.file}">
<patternset>
<include name="**"/>
<exclude name="META-INF/*.SF"/>
<exclude name="META-INF/*.DSA"/>
<exclude name="META-INF/*.RSA"/>
</patternset>
</unjar>
<delete file="@{jar}" failonerror="true"/>
<!-- Touch it in case the file didn't have a manifest.
Otherwise the JAR task below will fail if the manifest
file doesn't exist. -->
<mkdir dir="${temp.file}/META-INF"/>
<touch file="${temp.file}/META-INF/MANIFEST.MF"/>
<jar destfile="@{jar}"
basedir="${temp.file}"
includes="**"
manifest="${temp.file}/META-INF/MANIFEST.MF"/>
<delete dir="${temp.file}" failonerror="true"/>
</sequential>
</macrodef>
<!--unsign single jar -->
<unsignjar jar="/some/location/file.jar"/>
<!--unsign and then re-sign fileset -->
<for param="file">
<path>
<fileset dir="lib" includes="**/*.jar"/>
</path>
<sequential>
<antcall target="unsignjar">
<param name="jar" value="@{file}"/>
</antcall>
<signjar
jar="@{file}"
alias="myalias"
storepass="mypass"
keystore="keystore"/>
</sequential>
</for>
@is-andrade
Copy link

Very good!

@amanminz
Copy link

Awesome. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment