如何使用可移植 JRE 打包可执行 jar?

发布于 2024-07-15 22:13:37 字数 96 浏览 5 评论 0 原文

我希望能够通过可执行 JAR 进行分发,而不必让用户升级到最新版本的 JRE。 如何将 JRE 打包到 JAR 中,以便他们可以在系统上未安装 JRE 的情况下运行该 jar?

I want to be able to distribute by executable JAR without having to make the user upgrade to the latest version of the JRE. How can I package a JRE into the JAR so that they can run the jar with no JRE installed on their system?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

肥爪爪 2024-07-22 22:13:37

Java Portable 放入子目录中,并使用批处理/bash 脚本或 Launch4j

Put Java Portable in a sub-directory and launch your jar using a batch/bash script or Launch4j.

烟─花易冷 2024-07-22 22:13:37

由于你需要一个jre来执行一个jar,恐怕这是不可能的。

我曾经使用过 izpacklaunch4j 制作一个 Windows EXE,它将与我的应用程序一起安装 jre。

As you need a jre to execute a jar, I'm afraid this is not possible.

I have once used izpack together with launch4j to make a Windows EXE that would install a jre with my application.

最好是你 2024-07-22 22:13:37

十年后我遇到了同样的问题,经过几天的寻找,显然仍然没有解决方案,这是我发现的最好的东西:

Bundle Java (the JRE) and Launch a Java App with 7zip SFX: Convert Java Apps到可执行文件 https ://mark.koli.ch/bundle-java-the-jre-and-launch-a-java-app-with-7zip-sfx

编辑

我找到了另一种方法它基于 Inno Setup 和 NetBeans,经常作为有关将 jar 转换为 exe 的搜索结果出现。 一切都是使用 NetBeans IDE 中的本机打包 完成的。

结果是一个独立的 .exe 安装程序 (YourProjectName.exe),它在 AppData\Local\YourProjectName 中创建一个文件夹。 在该文件夹中,您将找到启动程序(.exe),以及无需安装 Java 即可运行该软件的所有必需文件。

您应该使用与文章中所述完全相同的工具版本,否则它不起作用,至少对我来说不起作用。 另一件不清楚的事情是,你的项目必须是带有 Ant 的 Java 项目,至少我没有找到如何用 Gradle 或 Maven 来做。

另外,我必须安装旧的 i586 版本的 Java(我尝试了 JDK 1.8 i586 并且它有效),因为 JDK 13 在尝试运行该软件时会导致错误(缺少 dll)。 虽然我只尝试过 JDK 13 x64,但也许架构是问题而不是版本。 不管怎样,类似的情况也发生在 NetBeans 11 上,.exe 启动器不起作用,但是在查找并执行 .jar 时它确实起作用。 所以我最终使用了 NetBeans 8。

Ten years later I ran into the same problem, and after several days looking, apparently there is still no solution, this is the best thing I have found:

Bundle Java (the JRE) and Launch a Java App with 7zip SFX: Convert Java Apps to an Executable https://mark.koli.ch/bundle-java-the-jre-and-launch-a-java-app-with-7zip-sfx

Edit

I found another way to do it, based on Inno Setup and NetBeans, it often appears as a result of searches about converting jar to exe. Everything is done using Native Packaging in NetBeans IDE.

The result is a standalone .exe installer (YourProjectName.exe) that creates a folder in AppData\Local\YourProjectName. In that folder you will find the launcher, which is an .exe, and also all the necessary files to run the software without installing Java.

You should use exactly the same tools versions that says in the article, otherwise it does not work, at least not for me. The other thing that is not clear is that your project must be a Java with Ant proyect, at least I did not find how to do it with Gradle or Maven.

Also, I had to install an old i586 version of Java (I tried JDK 1.8 i586 and it worked) because JDK 13 causes errors (missing dll's) when trying to run the software. Although I only tried with JDK 13 x64, maybe architecture is the problem and not the version. Whatever, similar happened to NetBeans 11, the .exe launcher did not work, however when locating and executing the .jar it did work. So I ended up using NetBeans 8.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文