简体   繁体   English

剥离JRE与应用程序捆绑在一起 - 我可以省略什么?

[英]Stripping the JRE to be bundled with an application - what can I omit?

I've been bundling JRE with my app by simply copying the files from $JAVA_HOME/jre to my app's distribution. 我只是将$JAVA_HOME/jre的文件复制到我的应用程序发行版中,就一直在将JRE与我的应用程序捆绑在一起。 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). 这可能违背了Java的精神,但它通过确保我的应用程序在经过测试的JRE版本上运行来减少潜在问题(包括比特;我使用一些JNI,它要求JRE是32位版本)。

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: 实际上, $JAVA_HOME/jre/README.txt包含以下建议:

The files that make up the Java SE Runtime Environment are divided into two categories: required and optional. 组成Java SE运行时环境的文件分为两类:必需和可选。 Optional files may be excluded from redistributions of the Java SE Runtime Environment at the vendor's discretion. 可供供应商自行决定从Java SE运行时环境的重新分发中排除可选文件。

The following section contains a list of the files and directories that may optionally be omitted from redistributions with the Java SE Runtime Environment. 以下部分包含可以选择从Java SE运行时环境的重新分发中省略的文件和目录的列表。 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. ...当使用自定义启动器将Microsoft Windows上的JRE重新分发为私有应用程序运行时(其他应用程序无法访问)时,以下文件也是可选的。 These are libraries and executables that are used for Java support in Internet Explorer and Mozilla family browsers; 这些是用于Internet Explorer和Mozilla系列浏览器中的Java支持的库和可执行文件; these files are not needed in a private JRE redistribution. 私有JRE重新分发中不需要这些文件。

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? java/javaw.exe如何可选? How am I supposed to start a Java application without them? 如果没有它们我应该如何启动Java应用程序? Apparently I don't know something (likely), or the instructions are simply wrong. 显然我不知道某些事情(可能),或者指示是完全错误的。

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. 使用自定义启动器将Microsoft Windows上的JRE重新分发为私有应用程序运行时(其他应用程序无法访问)时,以下文件也是可选的。

If you embed the JVM (by linking against its shared libraries) in your own application, you do not need the standalone launcher executables. 如果在自己的应用程序中嵌入JVM(通过链接其共享库),则不需要独立的启动程序可执行文件。 I think Eclipse works that way, for example. 例如,我认为Eclipse就是这样运作的。

If your app uses the java executable (via a batch file for example), then you need them, of course. 如果您的应用程序使用java可执行文件(例如通过批处理文件),那么您当然需要它们。

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. 虽然这与问题没有严格关系,但对于删除“不需要的代码”的整个程序(或整个平台)优化,我发现ProGuard是一个很好的工具。 YMMV. 因人而异。

How to convert it into an executable using a tool like launch4j ? 如何使用launch4j之类的工具将其转换为可执行文件? A few more suggestions you find here (not in the accepted answer) 您在此处找到的更多建议(不在接受的答案中)

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

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