Java 在 Windows 可执行文件中嵌入 JRE?

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

Embed a JRE in a Windows executable?

javawindowsdeploymentexecutablesoftware-distribution

提问by perp

Suppose I want to distribute a Java application.

假设我想分发一个 Java 应用程序。

Suppose I want to distribute it as a single executable. I could easily build a .jar with both the application and all its external dependencies in a single file (with some Ant hacking).

假设我想将它作为单个可执行文件分发。我可以在一个文件中轻松构建一个包含应用程序及其所有外部依赖项的 .jar(使用一些 Ant hacking)。

Now suppose I want to distribute it as an .exe file on Windows. That's easy enough, given the nice tools out there (such as Launch4j and the likes).

现在假设我想在 Windows 上将它作为 .exe 文件分发。考虑到那里有很好的工具(例如 Launch4j 等),这很容易。

But suppose now that I also don't want to depend on the end user having the right JRE (or any JRE at all for that matter) installed. I want to distribute a JRE with my app, and my app should run on this JRE. It's easy enough to create a Windows installer executable, and embed a folder with all necessary JRE files in it. But then I'm distributing an installerand not a single-file app.

但是现在假设我也不想依赖于安装了正确的 JRE(或任何 JRE)的最终用户。我想用我的应用程序分发一个 JRE,我的应用程序应该在这个 JRE 上运行。创建 Windows 安装程序可执行文件并在其中嵌入一个包含所有必需 JRE 文件的文件夹非常容易。但是我分发的是安装程序而不是单文件应用程序。

Is there a way to embed both the application, anda JRE, into an .exe file acting as the application launcher (and not as an installer)?

有没有办法将应用程序JRE嵌入到充当应用程序启动器(而不是安装程序)的 .exe 文件中?

采纳答案by i_home

Try to use Avianand ProGuardtoolkits. Avian allows to embed lightweight virtual machine in you app. Linux, MacOS, Windows and iOS are supported. And ProGuard allows you to shrink large jar file to prepare to embed.

尝试使用AvianProGuard工具包。Avian 允许在您的应用程序中嵌入轻量级虚拟机。支持 Linux、MacOS、Windows 和 iOS。ProGuard 允许您缩小大型 jar 文件以准备嵌入。

回答by metismo

Quite a few options around, commercially this is very good:

周围有很多选择,商业上这是非常好的:

http://www.excelsior-usa.com/jet.html

http://www.excelsior-usa.com/jet.html

There are two key open source options GCJ and VMKit

有两个关键的开源选项 GCJ 和 VMKit

http://gcc.gnu.org/java/and http://vmkit.llvm.org/

http://gcc.gnu.org/java/http://vmkit.llvm.org/

Other more prolonged paths would include IKVM.NET:

其他更长的路径包括 IKVM.NET:

http://www.ikvm.net/

http://www.ikvm.net/

Which is a .NET JVM which can be statically compiled to an EXE

这是一个可以静态编译为 EXE 的 .NET JVM

回答by Jonik

Is there a way to embed both the application, and a JRE, into an .exe file acting as the application launcher (and not as an installer)?

有没有办法将应用程序和 JRE 嵌入到充当应用程序启动器(而不是安装程序)的 .exe 文件中?

If a commercial tool is ok for you, install4jsolves this problem very smoothly (see its "Features" page). It can generate bothapplication launchers and installers.

如果商业工具适合您,install4j可以非常顺利地解决这个问题(请参阅其“功能”页面)。它可以产生两个应用程序启动和安装。

I'd hate to repeat myself too much, so check e.g. this earlier answerwhere I plugged it (as installer builder, but it doesn't make much difference here).

我不想重复太多,所以请检查例如我插入它的早期答案(作为安装程序构建器,但在这里没有太大区别)。

Summary / bottom line: install4j can create native .exe launchers that absolutely do notdepend on a pre-installed JRE (or any other specific libs), and it offers flexible options for bundling (and detecting) JREs.

总结/底线:install4j 可以创建绝对依赖于预先安装的 JRE(或任何其他特定库)的本机 .exe 启动器,并且它提供了用于捆绑(和检测)JRE 的灵活选项。

回答by Thorbj?rn Ravn Andersen

JSmooth can do this according to the documentation. I have only tried it without an embedded JRE, but been very satisfied. It is scriptable with ant and we build on Linux.

JSmooth 可以根据文档执行此操作。我只在没有嵌入 JRE 的情况下尝试过,但非常满意。它可以用 ant 编写脚本,我们在 Linux 上构建。

http://jsmooth.sourceforge.net/features.php

http://jsmooth.sourceforge.net/features.php

回答by Kachwahed

You might take a look at: http://ulibgcj.sourceforge.net/uswt.htmlIt has micro-swt library that make easy to build GUI using SWTand have a look at Eclipse GCJ Builder

你可以看看:http: //ulibgcj.sourceforge.net/uswt.html它有 micro-swt 库,可以使用SWT轻松构建 GUI ,并查看Eclipse GCJ Builder

回答by Kachwahed

Install4j is a great tool for this kink of purpose.Also you could check out JSmooth or launch4j-all though I have tried to bundle jres with JSmooth and was not able to..

Install4j 是实现这一目的的绝佳工具。此外,您还可以查看 JSmooth 或 launch4j-all,尽管我曾尝试将 jres 与 JSmooth 捆绑在一起,但无法...

回答by SnakeDoc

I know I'm a little late to this party, however it looks like ej-technologies (love their stuff) has a new solution called exe4jwhich will do exactly as the OP wanted without any funny business needed.

我知道我参加这个聚会有点晚了,但是看起来 ej-technologies(喜欢他们的东西)有一个新的解决方案,称为exe4j它可以完全按照 OP 的要求执行,不需要任何有趣的业务。

http://www.ej-technologies.com/products/exe4j/overview.html

http://www.ej-technologies.com/products/exe4j/overview.html

If you are working in an OpenSource project, they provide free licenses (you just need to contact them). If it's a commercial project, then a license is required... but at $69 USD for a license, it's darn cheap and worth while imho.

如果你在一个开源项目中工作,他们会提供免费的许可证(你只需要联系他们)。如果它是一个商业项目,则需要许可证……但许可证的价格为 69 美元,它非常便宜,而且物有所值。

From their website:

从他们的网站:

If you want your own process name instead of java.exe in the task manager
and a user friendly task-bar grouping, exe4j does the job for you.

exe4j helps you with starting your Java applications in a safe way, displaying
native splash screens, detecting or distributing suitable JREs and JDKs,
startup error handling and much more.

回答by Andrejs

There's a new tool that does this: Packr
https://github.com/libgdx/packr

有一个新工具可以做到这一点:Packr
https://github.com/libgdx/packr

回答by TianaR

Netbeans allows a Java SE project to be packaged in a native application installer, embedding a JRE. It's here :https://netbeans.org/kb/docs/java/native_pkg.html:)

Netbeans 允许将 Java SE 项目打包在本机应用程序安装程序中,嵌入 JRE。它在这里:https: //netbeans.org/kb/docs/java/native_pkg.html:)