public
Created

Unsign a JAR with Ant

  • Download Gist
unsignjar.xml
XML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
<!-- 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>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.