rt.jar put on a Proguard diet losses 26 MB

Jeff Palmer jcpalmer at rochester.rr.com
Sun Dec 16 14:16:51 PST 2012


On Dec 15, 2012, at 5:22 PM, Alan Bateman wrote:

> On 15/12/2012 22:08, Jeff Palmer wrote:
>> :
>> 
>> 
>> rt.jar went from 50,469 KB to 24,207 KB.  That's a 52% reduction!  Copied new-rt.jar over rt.jar in java-lib, and my apps still work.  Anyone know why rt.jar is so big? Alignment or compression level maybe?
> rt.jar is not compressed by default.
> 
> -Alan.

Thanks, excellent!  This does mean I need to switch tools from Proguard to just Ant.  Proguard is good for shrink wrapping an application, but if I wish to build a stub application with embedded Java and application level libraries, it is a little too suffocating.  Plus,  licensing issues seem un-avoidable. 

If in Ant, you unjar rt. jar into a temp directory,  you can then carve it like a turkey & jar it back.  In the build.xml below, I got the un-compressed size to 24,383 KB, which goes down to 12,382 KB at compression level 9.  The application did seem a little sluggish to start.  Maybe just stick with no compression, then rely on whatever rt. jar is delivered inside of  (dmg ?) to do the compression.  After delivered, unpacked where space is unlimited with faster media.

You can easily get diminishing returns if you delete some tiny thing, then decide to reference in later in an update to the implementation jar.  Everyone may have different needs, so this exact recipe might be wrong for some.  If you are not using SQL, then there is a bunch of stuff not listed here to get rid of.

The more I think about this hybrid fixed jre install with just in time impl.jar, the more I like it.  Java Webstart is too complicated, fragile, & dependent on an installed jre.  Too bad release 10 on Mac is still not really good enough yet.  I'll just put this on ice till a good one comes along, and use JWS till then.

Michael Hall - PKZIP files can have 9 level of compression, or none.  If Oracle builds the library jars with no compression, then my earlier experiment which does not look like it should do anything just compressed the output at whatever level Proguard uses.

Jeff Palmer
WhatIf Squared LLC
- - - - - - - - - - - - - - - - - - - - - -

<?xml version="1.0" encoding="UTF-8"?>
<project name="RT Carver" default="full">
    <description>
        Dis-assemble and repackage rt.jar for embedded stub application
    </description>

    <property name="temp-dir"        value="temp"/>
    <property name="rt-original-jar" value="rt-original.jar"/>
    <!--
    java.home not pointing to release 10 right now use above
    <property name="rt-original-jar" value="${java.home}/lib/rt.jar"/>
    -->
    <!-- ======================= Un-Jar Section =========================== -->
    <target name="un-jar">
        <delete dir="${temp-dir}" quiet="true"/>
        <mkdir  dir="${temp-dir}"/>
        <unjar src="${rt-original-jar}" dest="${temp-dir}" />
    </target>
    <!-- ======================= Carving Section ========================== -->
    <target name="carve" depends="un-jar">
<!--   23.3  KB --> <delete dir="${temp-dir}/com/sun/activation"/>  
<!-- 2840.0  KB --> <delete dir="${temp-dir}/com/sun/corba"/>  
<!--    0.9  KB --> <delete dir="${temp-dir}/com/sun/demo"/>  
<!--  960.0  KB --> <delete dir="${temp-dir}/com/sun/jmx"/>  
<!--  596.0  KB --> <delete dir="${temp-dir}/com/sun/jndi"/>  
<!--   32.8  KB --> <delete dir="${temp-dir}/com/sun/management"/>  
<!--  861.0  KB --> <delete dir="${temp-dir}/com/sun/org/apache/bcel"/>  
<!-- 2560.0  KB --> <delete dir="${temp-dir}/com/sun/org/apache/xalan"/>  
<!-- 3320.0  KB --> <delete dir="${temp-dir}/com/sun/org/apache/xerces"/>  
<!-- 2050.0  KB --> <delete dir="${temp-dir}/com/sun/org/apache/xml"/>  
<!--  888.0  KB --> <delete dir="${temp-dir}/com/sun/org/apache/xpath"/>  
<!--  108.0  KB --> <delete dir="${temp-dir}/com/sun/org/glassfish"/>  
<!--  106.0  KB --> <delete dir="${temp-dir}/com/sun/org/omg"/>  
<!--    7.47 KB --> <delete dir="${temp-dir}/com/sun/rmi"/>  
<!--  108.0  KB --> <delete dir="${temp-dir}/com/sun/script"/>  
<!-- 6760.0  KB --> <delete dir="${temp-dir}/com/sun/xml"/>  

<!--  NEVER DELETE /java/util/concurrent (553 KB) ABSOLUTELY REQUIRED INTERNALLY -->
<!--  /java/applet (6.32 KB) REQUIRED, but maybe only because still using JWS -->  
<!--  /java/util/logging (91.9  KB) needed, but a partial launch occurs -->  
<!--    6.8  KB --> <delete dir="${temp-dir}/java/lang/annotation"/>  
<!--    3.15 KB --> <delete dir="${temp-dir}/java/lang/instrument"/>  
<!--   58.5  KB --> <delete dir="${temp-dir}/java/lang/management"/>  
<!--   93.1  KB --> <delete dir="${temp-dir}/java/rmi"/>  

<!--  both /javax/swing/plaf/metal (438 KB) & /javax/swing/plaf/synth (510 KB) are required; didn't even think of nuking plaf/basic -->  
<!--   66.7  KB --> <delete dir="${temp-dir}/javax/activation"/>  
<!--   15.4  KB --> <delete dir="${temp-dir}/javax/annotation"/>  
<!--  226.0  KB --> <delete dir="${temp-dir}/javax/imageio"/>  
<!--  878.0  KB --> <delete dir="${temp-dir}/javax/management"/>  
<!--  171.0  KB --> <delete dir="${temp-dir}/javax/naming"/>  
<!--  195.0  KB --> <delete dir="${temp-dir}/javax/printing"/>  
<!--   29.1  KB --> <delete dir="${temp-dir}/javax/rmi"/>  
<!--   23.9  KB --> <delete dir="${temp-dir}/javax/script"/>  
<!--   23.9  KB --> <delete dir="${temp-dir}/javax/smartcardio"/>  
<!--   93.0  KB --> <delete dir="${temp-dir}/javax/swing/plaf/multi"/>  
<!--  700.0  KB --> <delete dir="${temp-dir}/javax/swing/plaf/nimbus"/>  
<!--   27.8  KB --> <delete dir="${temp-dir}/javax/tools"/>  
<!--  559.0  KB --> <delete dir="${temp-dir}/javax/xml"/>  

<!--  755.0  KB --> <delete dir="${temp-dir}/org/omg"/>  
<!--   81.3  KB --> <delete dir="${temp-dir}/org/w3c"/>  
<!--   79.5  KB --> <delete dir="${temp-dir}/org/xml"/>  

<!--  306.0  KB --> <delete dir="${temp-dir}/sun/applet"/>  
<!--   16.7  KB --> <delete dir="${temp-dir}/sun/audio"/>  
<!--   23.5  KB --> <delete dir="${temp-dir}/sun/beans"/>  
<!--    7.71 KB --> <delete dir="${temp-dir}/sun/corba"/>  
<!--   11.6  KB --> <delete dir="${temp-dir}/sun/instrument"/>  
<!--   95.1  KB --> <delete dir="${temp-dir}/sun/launcher"/>  
<!--  608.0  KB --> <delete dir="${temp-dir}/sun/management"/>  
<!--   58.1  KB --> <delete dir="${temp-dir}/sun/net/ftp"/>  
<!--  124.0  KB --> <delete dir="${temp-dir}/sun/net/httpserver"/>  
<!-- 1440.0  KB --> <delete dir="${temp-dir}/sun/org/mozilla"/>  
<!--  465.0  KB --> <delete dir="${temp-dir}/sun/print"/>  
<!--  415.0  KB --> <delete dir="${temp-dir}/sun/rmi"/>  
<!--   30.0  KB --> <delete dir="${temp-dir}/sun/tracing"/>  
<!--   15.2  KB --> <delete dir="${temp-dir}/sun/usagetracker"/>  

    </target>
    <!-- ======================= Re-Jar Section =========================== -->
    <target name="re-jar" depends="carve">
        <jar destfile="rt.jar" basedir="${temp-dir}" level="9"/>
    </target>
    <!-- ================================================================== -->
   <target name="full" depends="re-jar">
     <!--   <delete dir="${temp-dir}" quiet="true"/> -->
   </target>
</project>



More information about the macosx-port-dev mailing list