pack.xml.txt

<property name="jar" value="path/to/file.jar"/>
<property name="alias" value="alias"/>
<property name="password" value="secret"/>
<property name="keystore" value="path/to/keystore.jks"/>
<taskdef name="pack200" classname="com.sun.tools.apache.ant.pack200.Pack200Task" classpath="path/to/Pack200Task.jar"/>

<!--
  Sign the ${jar} Jarfile and create the file ${jar}.pack.gz
-->
<target name="pack">
 <echo file="${jar}.conf" append="false">
com.sun.java.util.jar.pack.verbose=0
com.sun.java.util.jar.pack.package.majver=150
com.sun.java.util.jar.pack.package.minver=7
pack.effort=9
pack.segment.limit=-1
 </echo>
 <pack200 configfile="${jar}.conf" src="${jar}" destfile="${jar}.tmp1.jar" repack="true"/>
 <signjar jar="${jar}.tmp1.jar" alias="${alias}" storepass="${password}" keystore="${keystore}"/>
 <pack200 stripdebug="true" configfile="${jar}.conf" src="${jar}.tmp1.jar" destfile="${jar}.tmp2.jar" repack="true"/>
 <signjar jar="${jar}.tmp2.jar" alias="${alias}" storepass="${password}" keystore="${keystore}"/>
 <pack200 stripdebug="true" configfile="${jar}.conf" gzipoutput="true" src="${jar}.tmp2.jar" destfile="${jar}.pack.gz"/>
 <delete quiet="true" file="${jar}.tmp1.jar"/>
 <delete quiet="true" file="${jar}.tmp2.jar"/>
 <delete quiet="true" file="${jar}.conf"/>
</target>