2

So here is what I did -

I unzipped the contents of rt.jar into a folder called rt. Then, inside rt folder, I executed the following jar command

jar cf rt.jar *

This should create a jar file with the same classes as that in the original rt.jar file.

However, the file sizes of the two files are significantly different.

Original rt.jar      -> 43.1 MB
Newly created rt.jar -> 20.6 MB

Note that the size of the unzipped contents for both the jar files is the same. This makes me think that the original rt.jar wasn't created using the jar command. So how was it created?

4

2 回答 2

7

原始 jar 使用 0 压缩级别创建,以减少加载类的 CPU 密集度。

> unzip -v rt.jar
Archive:  rt.jar
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Stored        0   0% 02-03-2012 21:20 00000000  META-INF/
    2343  Stored     2343   0% 02-03-2012 21:20 a653ef50  META-INF/MANIFEST.MF
     754  Stored      754   0% 02-03-2012 21:12 fa8ba6d9  com/oracle/net/Sdp$1.class
     350  Stored      350   0% 02-03-2012 21:12 ca729c09  com/oracle/net/Sdp$SdpSocket.class
...
于 2012-07-10T14:51:58.047 回答
7

它可能是使用-0jar 命令的选项创建的,该命令专门不应用 ZIP 压缩,而只是存储文件。

由于这个档案会被大量阅读,而且按照现代标准它非常小,为了 23MB,减少运行时开销似乎是值得的。

(无论如何,即使这不是严格正确的,文件大小的差异也会降低到不同的压缩级别。)

于 2012-07-10T14:49:40.823 回答