1

I have a jar file of size ~45MBs. I have used Pack200 to compress the jar file and then sign it with 3rd party certificate as follows :

pack200 --repack a.jar    
jarsigner  a.jar  ... ..    
pack200 a.jar.pack.gz a.jar

Using the above leads to an error as below (while launching applicaiont)

jarsigner: java.lang.SecurityException: SHA1 digest error for xyz.class

I need to use the pack200 compression as it will reduce the download time of jar to a great extent (after pack compression the jar size reduces to ~11MBs for ~45MBs).

Please help with this.
I am using java7u60 as runtime environment and JNLPs to lauch the JAR file.
Happy to provied any more informtion requried.

Dharmesh Porwal
  • 1,406
  • 2
  • 12
  • 21
Nayan Sonthalia
  • 237
  • 1
  • 4
  • 22
  • I believe that you are following this article http://docs.oracle.com/javase/tutorial/deployment/deploymentInDepth/reducingDownloadTime.html have you set the JNLP property? – MJSG Jan 09 '15 at 06:17
  • Yes, i am following that article as well as some links mentioned below. Also the JNLP has been set properly as per the article http://stackoverflow.com/questions/8952912/error-opening-library-file-compressed-with-pack200-compression; http://stackoverflow.com/questions/27084918/pack200-repack-leads-to-signature-verification-failure; https://blogs.oracle.com/manveen/entry/pack200_and_compression_through_ant. – Nayan Sonthalia Jan 09 '15 at 07:20

2 Answers2

0

i have figured out the solution...

Followiong is the ant script that i have used/created for the pack200

<project name="ui-patch-create" default="forloop">

<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<taskdef name="pack200" classname="com.sun.tools.apache.ant.pack200.Pack200Task" classpath="C:\Jarsigner\Pack200Task.jar"/>

    <description>UI Patch Creation</description>
    <property name="product.name" value="some product name"/>
    <property name="dest.path" value="C:\Jarsigner\dest"/>
    <property name="source.path" value="C:\Jarsigner"/>
    <property name="keystore" value="C:\Jarsigner\keystore\locationtokeystore"/>

    <target name="forloop">
        <foreach target= "CreateJAR" param="JAR-File">
            <fileset dir="${dest.path}" casesensitive="yes">
            </fileset> 
        </foreach>
    </target>

    <target name="CreateJAR">
        <echo message="${JAR-File}"/>
            <basename property="dir.name" file="${JAR-File}"/>  
                <echo message="${dir.name}"/>
                    <antcall target="Build-JAR">
                        <param name="param1" value="${dir.name}"/>
                    </antcall>
    </target>

    <target name="Build-JAR" depends="update-ui-jar,repack-jar, sign-jar, gzip-jar">
        <echo>
            Building the .jar file.
        </echo>
    </target>

<!-- Update ${JAR-File} file -->
    <target name="update-ui-jar">
        <unzip src="${dest.path}\${dir.name}" dest="${dest.path}\test">
            <patternset>
                <include name="**/MANIFEST.MF"/>
            </patternset>
        </unzip>

        <!-- meta-inf changes for supporting JAVA 7U45 and above...-->
        <manifest file="${dest.path}\test\META-INF\MANIFEST.MF" mode="update">
            <attribute name="Application-Name" value="Vendor Name"/>
            <attribute name="Codebase" value="*"/>
            <attribute name="Permissions" value="all-permissions"/>
            <attribute name="Trusted-Library" value="true"/>
            <attribute name="Caller-Allowable-Codebase" value="*"/>
        </manifest>

        <jar update="true" manifest="${dest.path}\test\META-INF\MANIFEST.MF" jarfile="${dest.path}\${dir.name}" basedir="${dest.path}\test" />
    </target>


<!-- Pack200 repack UI Jar File -->
    <target name="repack-jar" depends="update-ui-jar" description="applying pack200 --repack on jar ${dir.name}">
    <mkdir dir="${source.path}/repackedjars"/>
        <pack200 src="${dest.path}\${dir.name}" destfile="${source.path}/repackedjars/${dir.name}" repack="true" 
        segmentlimit="-1" stripdebug="false" deflatehint="keep" unknownattribute="pass" keepfileorder="true"/>
    </target>


<!-- Sign the UI Jar File -->
    <target name="sign-jar" depends="repack-jar">
        <echo message="${dir.name}"/>
            <signjar jar="${source.path}\repackedjars\${dir.name}" alias="xxxWS" keystore="${keystore}" storepass="storepass" keypass="xxxxxx" signedjar="${source.path}\signed\${dir.name}"/>
    </target>


    <!-- Pack200 to gzip UI Jar File -->
    <target name="gzip-jar" depends="sign-jar" description="applying gzip on jar ${dir.name}">
    <mkdir dir="${source.path}/finaljars"/>
        <pack200 src="${source.path}\signed\${dir.name}" destfile="${source.path}/finaljars/${dir.name}.pack.gz" gzipoutput="true"/>
    </target>

</project>

Please note that the antcontrin and pack200 tasks need to be download before using theis script and that the ant script should be executed on previously unsigned jars only.

Nayan Sonthalia
  • 237
  • 1
  • 4
  • 22
-2

You coud try to add --segment-limit=-1