剥离与应用程序捆绑的 JRE - 我可以省略什么?
我已经将 JRE 与我的应用程序捆绑在一起,只需将文件从 $JAVA_HOME/jre 复制到我的应用程序的发行版即可。这可能违背了 Java 的精神,但它通过确保我的应用程序在经过测试的 JRE 版本上运行(包括位数;我使用一些 JNI 来减少潜在的问题),这要求 JRE 是 32 位版本)。
它工作正常,但整个发行版有点大,所以也许可以省略一些不必要的文件?事实上,$JAVA_HOME/jre/README.txt
包含以下建议:
组成 Java SE 运行时环境的文件分为 两类:必需的和可选的。可选文件可能被排除 来自 Java SE 运行时环境的重新分发 供应商自行决定。
以下部分包含文件和目录的列表 可以选择从 Java SE 运行时的重新分发中省略 环境。所有不在这些可选文件列表中的文件都必须是 包含在运行时环境的重新分发中。
...在 Microsoft Windows 上将 JRE 作为私有资源重新分发时 应用程序运行时(其他应用程序无法访问) 使用自定义启动器,还可以使用以下文件 选修的。这些是使用的库和可执行文件 Internet Explorer 和 Mozilla 系列浏览器中的 Java 支持; 私有 JRE 重新分发中不需要这些文件。
让我困惑的是,可选文件列表包括:
bin\java.exe
bin\javaw.exe
bin\javaws.exe
java/javaw.exe 如何成为可选的?如果没有它们,我该如何启动 Java 应用程序?显然我不知道什么(可能),或者说明根本就是错误的。
I've been bundling JRE with my app by simply copying the files from $JAVA_HOME/jre
to my app's distribution. This may be against the spirit of Java, but it reduces potential problems by ensuring that my app runs on a version of JRE that it was tested on (including the bitness; I use some JNI which requires that the JRE is a 32-bit version).
It works fine, but the whole distribution is somewhat big, so maybe some unnecessary files could be left out? Indeed, $JAVA_HOME/jre/README.txt
contains the following advice:
The files that make up the Java SE Runtime Environment are divided into
two categories: required and optional. Optional files may be excluded
from redistributions of the Java SE Runtime Environment at the
vendor's discretion.The following section contains a list of the files and directories that
may optionally be omitted from redistributions with the Java SE Runtime
Environment. All files not in these lists of optional files must be
included in redistributions of the runtime environment....When redistributing the JRE on Microsoft Windows as a private
application runtime (not accessible by other applications)
with a custom launcher, the following files are also
optional. These are libraries and executables that are used
for Java support in Internet Explorer and Mozilla family browsers;
these files are not needed in a private JRE redistribution.
What puzzles me is that the list of optional files includes, among others:
bin\java.exe
bin\javaw.exe
bin\javaws.exe
How can java/javaw.exe
be optional? How am I supposed to start a Java application without them? Apparently I don't know something (likely), or the instructions are simply wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将 JVM(通过链接其共享库)嵌入到您自己的应用程序中,则不需要独立的启动程序可执行文件。例如,我认为 Eclipse 就是这样工作的。
如果您的应用程序使用 java 可执行文件(例如通过批处理文件),那么您当然需要它们。
If you embed the JVM (by linking against its shared libraries) in your own application, you do not need the standalone launcher executables. I think Eclipse works that way, for example.
If your app uses the java executable (via a batch file for example), then you need them, of course.
虽然这与问题并不严格相关,但对于删除“不需要的代码”的整个程序(或整个平台)优化,我发现 ProGuard 是一个很好的工具。 YMMV。
While this doesn't strictly relate to the question, for whole-program (or whole-platform) optimization of removing "un-needed code", I have found ProGuard to be a good tool. YMMV.