java 适用于 Windows 的最小精简 JRE

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12953748/
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-31 10:57:07  来源:igfitidea点击:

A minimal Stripped Down JRE for Windows

deploymentjavasoftware-distribution

提问by user93353

I have an application in the form of a jar file which is around 2MB in size. For several reasons, I have to bundle the JRE with my application. When I create an MSI with my jar and the JRE, the MSI size comes out to be around 30MB.

我有一个大小约为 2MB 的 jar 文件形式的应用程序。出于多种原因,我必须将 JRE 与我的应用程序捆绑在一起。当我使用 jar 和 JRE 创建 MSI 时,MSI 大小约为 30MB。

I am looking for a commercial or free JRE which I can bundle so that I can reduce the size of my MSI to as low as possible. I am looking at 5MB total, but even upto 10MB may be OK. Prebuilt JRE Binaries would be great, but not an absolute must.

我正在寻找可以捆绑的商业或免费 JRE,以便我可以将 MSI 的大小减小到尽可能小。我正在查看总共 5MB,但即使高达 10MB 也可以。预构建的 JRE 二进制文件会很棒,但不是绝对必须的。

I looked at similar questions posted hereand here.

我查看了此处此处发布的类似问题。

A lot of answers in these and other threads suggest Excelsior. I downloaded an evaluation version of Excelsior JET & Tried it out - for a few reasons, I think it may not be the right product for me.

这些主题和其他主题中的许多答案都建议使用 Excelsior。我下载了 Excelsior JET 的评估版并试用了它 - 由于一些原因,我认为它可能不是适合我的产品。

1) Excelsior looks at reducing the footprint of the Installed Product not the Installer. I don't care much about the size of the Installed Product - I am mainly looking at a smaller download (the installer of my product currently at 30MB).

1) Excelsior 着眼于减少已安装产品而不是安装程序的占用空间。我不太关心已安装产品的大小 - 我主要关注较小的下载(我的产品安装程序目前为 30MB)。

2) Amongst other things, Excelsior does lot of optimizations to code to achieve this - I don't want my jar file touched at all. I want a smaller JRE with my jar as is. There isn't a way to turn off some of the optimisations also.

2) 除此之外,Excelsior 对代码做了很多优化来实现这一点——我根本不希望我的 jar 文件被触及。我想要一个较小的 JRE 和我的罐子。也没有办法关闭一些优化。

3) Excelsior creates an EXE - I am not particularly looking for this - I am ok with my product being invoked via the javaw.exe command line.

3) Excelsior 创建了一个 EXE - 我并不是特别想要这个 - 我对通过 javaw.exe 命令行调用我的产品没问题。

So are there any suggestions for my need?

那么对我的需求有什么建议吗?

回答by stackmagic

Avian and ProGuard are your friends as someone has already mentionedin one of the threads you linked to (it's the second comment btw).

Avian 和 ProGuard 是您的朋友,因为有人已经在您链接到的主题之一中提到过(顺便说一句,这是第二条评论)。

From the Avian homepage:

从 Avian 主页:

The class library is designed to be as loosely coupled as possible, allowing tools like ProGuard to aggressively isolate the minimum code needed for an application. This translates to smaller downloads and faster startup.

类库被设计为尽可能松散耦合,允许 ProGuard 等工具积极隔离应用程序所需的最少代码。这意味着更小的下载和更快的启动。

Sounds like exactly what you need. And if that doesn't help you then look at the rest of the tools referenced in that thread.

听起来正是您所需要的。如果这对您没有帮助,请查看该线程中引用的其余工具。

回答by Migrate2Lazarus see my profile

There is a possible solution here. Those tools install a minimalistic version of Java. I don't know if it is small enough for you. Just take a look and see: https://superuser.com/questions/745112/how-do-i-run-a-jar-file-without-installing-java

这里有一个可能的解决方案。这些工具安装 Java 的简约版本。我不知道它对你来说是否足够小。看一看:https: //superuser.com/questions/745112/how-do-i-run-a-jar-file-without-installing-java

回答by Peter Lawrey

I would make the JRE a separate install from Oracle (or your preferred vendor) You could have it download as required if you wish. If the JRE is already installed, it would be a waste to download it again even a reduced JRE.

我会将 JRE 与 Oracle(或您首选的供应商)分开安装 如果您愿意,可以根据需要下载它。如果已经安装了JRE,即使是精简版的JRE,再次下载也是一种浪费。

BTW: I wouldn't mess with what is in the JRE because

顺便说一句:我不会弄乱 JRE 中的内容,因为

  • AFAIK its a violation of your license agreement.
  • Its very difficult to get right and not remove a class you might need one day.
  • AFAIK 违反了您的许可协议。
  • 很难做到正确并且不删除您有一天可能需要的课程。