File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes reducing the  size of rt.jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "reducing the  size of rt.jar" Watch "reducing the  size of rt.jar" New topic

reducing the size of rt.jar

Srikanth Ravi

Joined: Jul 22, 2002
Posts: 1
In the rt.jar file I dont require some of the packages like corba and rmi. To solve this problem what I did was I unjarred the rt.jar file , removed those packages and again jarred into new-rt.jar. The size of rt.jar was 11MB and the size of new-rt.jar was 5MB. now i tried to zip both the jar files, the results were like this . The size of was 3.6MB and the size of was 4.8MB. I am not able to understand why this 5MB file is not getting compreseed much compared to the 11MB file. Is there any way I am doing wrong while I unjar the rt.jar and again jar into new-rt.jar.These are the statements I am using for doing that
jar -xvf rt.jar
jar -cvf new-rt.jar <dir1><dir2><dir3>
please let me know if there is any suggestion...
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
For some reason it looks like your original rt.jar was not a compressed jar file, but your new one is.
By default the "jar" command compresses the output. I reckon that the major size reduction you saw was mainly due to that. I can't believe that half of rt.jar was taken up by just corba and rmi. There's a whole lot of other stuff (like the Java compiler) in there!

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
IANAL (I am not a lawyer) but I suggest you read the licensing agreement from Sun about the use of their Java (tm) Technology products! What you are doing is specifically prohibited! You are creating a "custom" distribution, and this is basically what MS tried to do with their "dirty" java and that's why Sun sued them.
Besides that little fact, you should be aware of a few things:
1) jar files = gzip archives
2) gzip archives use LZW compression, and one of the results of this is that in order to sequentially access any element of the archive, the entire archive must be uncompressed first. Think about that for a moment.
Not *every* class in rt.jar needs to be loaded during the execution of your java app, and the system class loader loads classes as needed. If it needs to load a class file from rt.jar and it's compressed, the entire file must first be uncompressed in order for the Class file to be located and loaded.
That's why you should NOT compress your jar files, unless you're using them for an applet. That's really the only valid use of compressing jar files (or other network distributed uses where bandwith is limited). If you're including your own libraries in jar files for an app you are distributing say via a CD-ROM, you still won't compress the Jar files. If you are using an installer, the *entire* installation package might be compressed but the individual jar files themselves should not be.
I hope this clears things up for you.
[ July 23, 2002: Message edited by: Rob Ross ]

SCJP 1.4
I agree. Here's the link:
subject: reducing the size of rt.jar
It's not a secret anymore!