在 Windows 可执行文件中嵌入 JRE?
假设我想分发一个 Java 应用程序。
假设我想将其作为单个可执行文件分发。我可以轻松地在单个文件中构建一个包含应用程序及其所有外部依赖项的 .jar(使用一些 Ant 黑客技术)。
现在假设我想在 Windows 上将其作为 .exe 文件分发。鉴于有很好的工具(例如 Launch4j 等),这很容易。
但现在假设我也不想依赖最终用户安装了正确的 JRE(或任何 JRE)。我想随我的应用程序一起分发 JRE,并且我的应用程序应该在该 JRE 上运行。创建 Windows 安装程序可执行文件并嵌入一个包含所有必需 JRE 文件的文件夹非常简单。但随后我分发的是安装程序,而不是单文件应用程序。
有没有办法将应用程序(和 JRE)嵌入到充当应用程序启动器(而不是安装程序)的 .exe 文件中?
Suppose I want to distribute a Java application.
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).
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).
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 installer and not a single-file app.
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
尝试使用 Avian 和 ProGuard 工具包。
Avian 允许在您的应用程序中嵌入轻量级虚拟机。支持 Linux、MacOS、Windows 和 iOS。 ProGuard 允许您缩小大型 jar 文件以准备嵌入。
Try to use Avian and ProGuard toolkits.
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.
有一个新工具可以执行此操作:Packr
https://github.com/libgdx/packr
There's a new tool that does this: Packr
https://github.com/libgdx/packr
有相当多的选择,商业上这非常好:
http://www.excelsior-usa.com /jet.html
有两个关键的开源选项 GCJ 和 VMKit
http://gcc.gnu。 org/java/ 和 http://vmkit.llvm.org/
其他更长的路径将包括 IKVM.NET:
http://www.ikvm.net/
这是一个 .NET JVM,可以静态编译为 EXE
Quite a few options around, commercially this is very good:
http://www.excelsior-usa.com/jet.html
There are two key open source options GCJ and VMKit
http://gcc.gnu.org/java/ and http://vmkit.llvm.org/
Other more prolonged paths would include IKVM.NET:
http://www.ikvm.net/
Which is a .NET JVM which can be statically compiled to an EXE
我自己遇到问题后 -
1)创建一个包含应用程序 jar 文件的文件夹
2)创建一个包含 jre 的子文件夹
3)创建一个在应用程序使用期间覆盖 env 变量的 bat 文件
并将启动您的应用程序:
4)使用bat到exe转换器
选项包括:
https://listoffreeware.com/6-best-free- bat-exe-converter-software-windows/
第一个选项在这里可用:
https://web.archive.org/web/20190305143030/http://www.f2ko.de/downloads/Bat_To_Exe_Converter.zip
5)创建一个exe包含该文件夹并在运行时运行 bat 文件
After encountering the issue myself -
1)create a folder containing your application jar file
2)create a subfolder containing the jre
3)create a bat file that overwrites env variables for the duration of application usage
and will launch your application:
4)use bat to exe converter
options include:
https://listoffreeware.com/6-best-free-bat-exe-converter-software-windows/
the first option is avaliable here:
https://web.archive.org/web/20190305143030/http://www.f2ko.de/downloads/Bat_To_Exe_Converter.zip
5)create an exe that contains the folder and runs the bat file when run
如果商业工具适合您,install4j 可以很好地解决这个问题顺利(请参阅其“功能”页面)。它可以生成两者应用程序启动器和安装程序。
我不想重复太多,所以检查例如 这个早期的答案,我将其插入其中(作为安装程序生成器,但在这里没有太大区别)。
摘要/底线:install4j 可以创建绝对不依赖于预安装 JRE(或任何其他特定库)的本机 .exe 启动器,并且它提供了用于捆绑(和检测)JRE 的灵活选项。
If a commercial tool is ok for you, install4j solves this problem very smoothly (see its "Features" page). It can generate both application launchers and installers.
I'd hate to repeat myself too much, so check e.g. this earlier answer where 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 not depend on a pre-installed JRE (or any other specific libs), and it offers flexible options for bundling (and detecting) JREs.
Netbeans 允许将 Java SE 项目打包在本机应用程序安装程序中,嵌入 JRE。
它在这里:https://netbeans.org/kb/docs/java/native_pkg.html< /a>:)
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 :)
我编写了一个具有以下内容的解决方案:
由于 exe 文件非常小,您可以构建一次并将其放入存储库中。除非您重命名主 Java 类或想要更改图标,否则不需要更新它。
您部署的应用程序将如下所示:
您可以在此处查看:https://github。 com/foolo/windows-jre-laucher
I wrote a solution that has the following:
Since the exe file is so tiny, you can build it once and put it the repo. You won't need to update it unless you rename the main Java class or want to change icon.
Your deployed application would look something like this:
You can check it out here: https://github.com/foolo/windows-jre-laucher
另一个例子... 捆绑 Java(JRE)并使用 7zip SFX 启动 Java 应用程序! ...(将 Java 应用程序转换为可执行文件)
Another example... Bundle Java (the JRE) and Launch a Java App with 7zip SFX! ... (Convert Java Apps to an Executable, sort of)
我知道我参加这个聚会有点晚了,但是看起来 ej-technologies(喜欢他们的东西)有一个名为
exe4j
的新解决方案,它将完全按照 OP 的要求进行操作,而不需要任何有趣的业务。http://www.ej-technologies.com/products/exe4j/overview.html
如果您在开源项目中工作,他们会提供免费许可证(您只需联系他们)。如果它是一个商业项目,那么就需要许可证......但许可证的价格为 69 美元,恕我直言,它非常便宜且值得。
从他们的网站:
I know I'm a little late to this party, however it looks like ej-technologies (love their stuff) has a new solution called
exe4j
which will do exactly as the OP wanted without any funny business needed.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.
From their website:
我发现 Engima Projector x86 / x64 比 BoxedApp Packer 更好
如果您通过 packr 获得软 miminizejre,则将应用程序 myapp.jar 复制到 launcher\jre\bin\
并从已安装的 jre 示例 C:\Program Files\Files\Java\1.8 中复制。 0_xxx\bin\javaw.exe 到 launcher\jre\bin\
打开 Engima Protector 输入 ->来自启动器\jre\bin\ 的 javaw.exe
如果您想要高压缩和,请转到选项
查找杂项 ->命令行“-jar myapp.jar”
然后单击“保护”并等待整个 dll 和 jar 进入 exe
确保您的 myapp.jar 应该由 Eclipse 生成,并带有“将所需的库打包到生成的 JAR 中”,因为您不必担心是否已导入许多库(例如 lwjgl 或 JavaFX)比您必须检查嵌入式 javaw_protected.exe 是否包含重要文件示例资产。
但 BoxedApp Packer 也一样 BoxedApp Packer 比 Engima Protector 大一点。 Protector 几乎是最好的小型嵌入 javaw.exe 的资产/资源。比他们无法破解 jar 文件...我希望你对自己的 jar 到 exe 中感到满意,因为没有 lib 目录,只有 4 mb - 如果你对 jvm.cfg 错误消息有问题,这意味着你没有将嵌入的 exe 复制到根目录中jre 或 jdk 目录
请确保嵌入的 exe 位于 jre 或 jdk 根目录之外。
我希望如果您使用 Protector x86 而不需要使用 i586,Protector x64 for jre x64
如果您将 Protector x64 与 jre x86/i386 一起使用 - 没关系,没问题。效果很好。
最好的问候
// 编辑:
更新的新版本 EXCELSIOR JET + 虚拟盒或保护器几乎是最好的“嵌入式应用程序”
检查 youtube:https://www.youtube.com/watch?v=ctbIxq-1MGE
I found Engima Projector x86 / x64 better than BoxedApp Packer
If you get soft miminizejre by packr than copy your application myapp.jar into launcher\jre\bin\
and copy from installed jre example C:\Program Files\Files\Java\1.8.0_xxx\bin\javaw.exe to launcher\jre\bin\
Open Engima Protector input -> javaw.exe from launcher\jre\bin\
And go Options if you want high compress and
Find Miscellaneous -> Command line "-jar myapp.jar"
And click protect and wait for whole dlls and jar into exe
Make sure your myapp.jar should generate by Eclipse with "Package required libraries into generated JAR" because you don't worry if you have imported many libraries example lwjgl or JavaFX than you must check if embedded javaw_protected.exe has included important files example assets.
But BoxedApp Packer is same too BoxedApp Packer is bit bigger than Engima Protector. Protector is almost best small embedding javaw.exe with assets / resources. Than they can't crack jar files... I hope you are happy with own jar into exe as less 4 mb without lib directory - If you have problem with jvm.cfg error message It means you don't copy embedded exe into root directory of jre or jdk
Please make sure embedded exe is here outside of jre or jdk root directory.
I hope you haven't problem if you use Protector x86 than it need use i586, Protector x64 for jre x64
If you use Protector x64 with jre x86/i386 - It is okay no problem. It works fine.
Best regards
// EDIT:
UPDATED NEW VERSION EXCELSIOR JET + VIRTUAL BOX OR PROTECTOR are almost best "embedded applications"
Check youtube: https://www.youtube.com/watch?v=ctbIxq-1MGE
JSmooth可以根据文档做到这一点。我只在没有嵌入式 JRE 的情况下尝试过,但非常满意。它可以使用 ant 编写脚本,并且我们在 Linux 上构建。
http://jsmooth.sourceforge.net/features.php
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.
http://jsmooth.sourceforge.net/features.php
您可能会看一下:
http://ulibgcj.sourceforge.net/uswt.html
它具有 micro-swt 库,可以使用 SWT 轻松构建 GUI
并查看 Eclipse GCJ Builder
You might take a look at:
http://ulibgcj.sourceforge.net/uswt.html
It has micro-swt library that make easy to build GUI using SWT
and have a look at Eclipse GCJ Builder
Install4j 对于这种目的来说是一个很棒的工具。您也可以查看 JSmooth 或 launch4j-all,尽管我尝试将 jres 与 JSmooth 捆绑在一起但无法..
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..