简体   繁体   English

从jre的rt.jar中删除未使用的类

[英]remove unused class from rt.jar in jre

i tried to remove unused .class files from rt.jar and bundle it to my program but there are 2 problems: 我试图从rt.jar中删除未使用的.class文件并将其捆绑到我的程序中,但是有2个问题:

  1. java is a JIT language and some required libs will load after some process like click and ... so if you delete files with ERROR-SUCCESS method you will fail. java是一种JIT语言,某些必需的库将在诸如click和...之类的过程之后加载,因此,如果使用ERROR-SUCCESS方法删除文件,则将失败。

  2. many of classess needed by java runtime for first prepration. Java运行时首次准备所需的许多类。

so how i can find out which of class files are not required? 所以我如何找出哪些类文件不是必需的?

Have look at Bundling a minimal 'bare bones' JVM with your Application to do what you want. 看一下将最小的“裸露的” JVM与您的应用程序捆绑在一起以完成所需的操作。 The author narrowed down a "Hello World" application to a 5MB JVM. 作者将“ Hello World”应用程序缩小为5MB JVM。 That might not be legal to distribute however, you should probably check into that first. 分发该文件可能不合法,但是您应该首先检查一下。

You might also want to consider just including or linking to the online installer. 您可能还需要考虑仅包括或链接到在线安装程序。 For Windows it's under 1MB and available here . 对于Windows,它不到1MB,可在此处下载

Don't bundle rt.jar. 不要捆绑rt.jar。 You don't need to. 不用了 It's already distributed with the Java Virtual Machine, and anyone who can run your program already has it. 它已经随Java虚拟机一起分发,并且可以运行您的程序的任何人都已经拥有它。

On my machine, my rt.jar is about 48meg. 在我的机器上,我的rt.jar约为48兆。 I can understand why you wouldn't want to bundle an additional 48meg. 我能理解为什么您不希望再捆绑48兆欧。 However, I did a 7zip compress (default settings in the context menu) and because it's just code, which compresses very well, it compressed down to 10meg. 但是,我进行了7zip压缩(上下文菜单中的默认设置),并且因为它只是压缩得很好的代码,所以压缩到10兆像素。

I would suggest simply compressing and then decompressing on install. 我建议您在安装时先压缩然后再解压缩。

Edit: The entire jre (which I'm assuming you'll need, but that you've already trimmed what files you don't need) compressed to about 21 meg. 编辑:整个jre(我假设您需要,但是您已经修剪了不需要的文件)压缩到大约21兆。

您不能只捆绑rt.jar,而必须捆绑整个JRE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM