Currently, I am writing an Ant Script that removes the signatures of signed Jar files.
Removing the signature for a single jar file was successful using the script below.
<project name="unsign">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="ant-lib/ant-contrib-0.6.jar" />
<property name="jarPath" location="C:\Users\Administrator\Desktop\tempDir" />
<property name="resultPath" location="C:\Users\Administrator\Desktop\tempDir-result" />
<target name="unsignJar">
<unsignjar jarFile="${jarPath}/com.google.guava_15.0.0.v201403281430.jar" />
</target>
<macrodef name="unsignjar" description="Unsign a jar file">
<attribute name="jarfile" description="Jar file to unsign " />
<sequential>
<copy toFile="@{jarFile}_MANIFEST.tmp">
<resources>
<zipentry zipfile="@{jarFile}" name="META-INF/MANIFEST.MF" />
</resources>
</copy>
<replaceregexp file="@{jarFile}_MANIFEST.tmp" match="\nName:(.+?)\nSH" replace="SH" flags="gis" byline="false" />
<replaceregexp file="@{jarFile}_MANIFEST.tmp" match="SHA(.*)" replace="" flags="gis" byline="false" />
<jar jarfile="@{jarFile}.tmp" manifest="@{jarFile}_MANIFEST.tmp">
<zipfileset src="@{jarFile}">
<include name="**" />
<exclude name="META-INF/*.SF" />
<exclude name="META-INF/*.DSA" />
<exclude name="META-INF/*.RSA" />
</zipfileset>
</jar>
<!-- Removing the temporary manifest -->
<delete file="@{jarFile}_MANIFEST.tmp" />
<!-- Swapping the original Jar file with the temporary one -->
<move file="@{jarFile}.tmp" tofile="@{jarFile}" overwrite="true" />
</sequential>
</macrodef>
</project>