java 减少 JRE 的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4387266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 06:08:30  来源:igfitidea点击:

Reducing size of JRE

jvmjava

提问by asela38

We bundle the Java 6 JRE with our application installer so that it can be run on any machine, but this makes the application a little bit heavier. So we are planning to reduce the size of the JRE. If anyone has done this sort of task, can you please provide guidance to move forward with this?

我们将 Java 6 JRE 与我们的应用程序安装程序捆绑在一起,以便它可以在任何机器上运行,但这会使应用程序变得更重一些。所以我们计划减少 JRE 的大小。如果有人完成过此类任务,您能否提供指导以推进这项工作?

回答by AngerClown

Look at the README file in the JRE directory. The 'Optional Files and Directories' section lists a number of files that can be removed from the Oracle/Sun JRE if you are packaging it with your application.

查看 JRE 目录中的 README 文件。如果您将 Oracle/Sun JRE 与应用程序一起打包,则“可选文件和目录”部分列出了许多可以从 Oracle/Sun JRE 中删除的文件。

I use an Ant buildfile to copy the JRE from the system install location to the package directory when creating an installation. Put the list of files you want excluded in a separate file and use the 'excludesfile' attribute to load this list:

在创建安装时,我使用 Ant 构建文件将 JRE 从系统安装位置复制到包目录。将要排除的文件列表放在单独的文件中,并使用“excludesfile”属性加载此列表:

<copy todir="${deployed_jre_dir}">
  <fileset dir="${system_jre_dir}" excludesfile="jre_excludes.properties" 
</copy>

Sample jre_excludes.properties file:

示例 jre_excludes.properties 文件:

# per the README from the JRE, these files are for the browser plugin and are not needed otherwise
#bin/javaw.exe
bin/javaws.exe
bin/javacpl.exe
bin/jucheck.exe
bin/jusched.exe
bin/wsdetect.dll
bin/NPJPI*.dll
bin/NPJava*
bin/NPOJI610.dll
bin/RegUtils.dll
bin/axbridge.dll
bin/deploy.dll
bin/jpicom.dll
bin/javacpl.cpl
bin/jpiexp.dll
bin/jpinscp.dll
bin/jpioji.dll
bin/jpishare.dll
lib/deploy.jar
lib/plugin.jar
lib/javaws.jar
lib/javaws/messages*
lib/javaws/miniSplash.jpg
bin/new_plugin**
bin/jureg*
bin/ssv*
bin/jqs*
bin/jp2*
lib/deploy/**/*

# if you do not need any RMI stuff
# wildcard to catch .exe files on Windows
# note rmi.dll is not excluded, which is needed by jconsole; add rmi.dll if you do not need jsonsole
bin/jbroker*
bin/java-rmi*
bin/rmid*
bin/rmiregistry*
bin/tnameserv*
bin/orbd*
bin/servertool*

# do not include QuickTime
# this will be in the jre dir for machines that have QT installed
lib/ext/QTJava.zip

回答by Roman K

Some update info: since java 8 there is an official Oracle tool called jrecreatefor creating of small embedded JRE packages.

一些更新信息:从 java 8 开始,有一个名为jrecreate的官方 Oracle 工具,用于创建小型嵌入式 JRE 包。

回答by Reto H?hener

For my Java 8 Update 144 desktop application I exclude the 2 big Java FX files:

对于我的 Java 8 Update 144 桌面应用程序,我排除了 2 个大的 Java FX 文件:

   bin/jfxwebkit.dll // ~34 MB unpacked
   lib/ext/jfxrt.jar // ~17 MB unpacked

The zipped jre is 49 MB instead of 66 MB.

压缩后的 jre 是 49 MB 而不是 66 MB。

For me this is an acceptable tradeoff between reduced size and added build complexity (and potential bugs).

对我来说,这是减小尺寸和增加构建复杂性(和潜在错误)之间的可接受的折衷。

回答by darioo

You're trying to reduce a standard JRE's size? Don't do that. You can choose to bundle an alternative JRE which might be smaller. A list can be found on this Wikipedia page. As always, beware of compatibility issues and test your application thoroughly.

您正在尝试减小标准 JRE 的大小?不要那样做。您可以选择捆绑一个可能更小的替代 JRE。可在此 Wikipedia 页面上找到列表。与往常一样,请注意兼容性问题并彻底测试您的应用程序。

An other, and safer, way is to just require an installation of a JRE on the target machine.

另一种更安全的方法是只需要在目标机器上安装 JRE。