如何将 JRE 捆绑到 Java 应用程序的 EXE 中?Launch4j 说“运行时丢失或损坏". [英] How do I bundle a JRE into an EXE for a Java Application? Launch4j says "runtime is missing or corrupted."

查看:26
本文介绍了如何将 JRE 捆绑到 Java 应用程序的 EXE 中?Launch4j 说“运行时丢失或损坏".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Java 编程的新手,但大体上熟悉一切工作原理.我希望能够将 jar 文件和 jre 放入 windows 可执行文件(exe)中,以便在分发它时,客户端不需要安装 JRE.我应该使用什么程序?

I am new to programming in Java but am generally familiar with how everything works. I would like to be able to put both a jar file and a jre into a windows executable(exe) so that when I distribute it, the client needn't have a JRE installed. What program should I use?

我有 launch4j 并且它似乎完全符合我的要求,但是当我尝试运行该应用程序时,我收到此应用程序配置为使用捆绑的 Java 运行时环境,但运行时丢失或损坏."

I have launch4j and it seems to do exactly what I want but when I try to run the app, I get "This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted."

我希望我的应用程序只是一个可运行的 exe,而不是一个安装程序.至少,谁能告诉我如何正确地将 JRE 与 launch4j 捆绑在一起?

I want my app to just be a runnable exe, not an installer. At the very least, can anyone show me how to correctly bundle a JRE with launch4j?

推荐答案

我可以捆绑 JRE 的唯一方法是使用 Launch4JInno Setup Compiler.

The only way I could bundle a JRE was to use Launch4J and Inno Setup Compiler.

首先,在与输出文件 (.exe) 相同的目录中创建一个 jre6 文件夹(例如).

First, create a jre6 folder (for example) in the same directory as your output file (.exe).

然后将 JRE 从您的系统复制到您的 jre6 文件夹中.

Then copy the JRE from your system into your jre6 folder.

然后打开 Launch4J 并设置 Bundled JRE 路径 - 只需输入 jre6.然后单击构建"按钮(显然,在您输入所有其他参数之后 - 但您需要在 JRE 选项卡本身上输入的唯一值是 Bundled JRE 路径值.)

Then you open Launch4J and set the Bundled JRE path - just type in jre6. Then click the Build button (obviously, after you've entered all the other parameters - but the only value you need to enter on the JRE tab itself is the Bundled JRE path value.)

我本来希望它可以工作,但是如果您随后将 .exe 移动到新位置(因此它不再与您的 jre6 文件夹位于同一位置),您将获得 此应用程序被配置为使用捆绑的 Java 运行时环境,但当您尝试运行该应用程序时,运行时丢失或损坏错误...

I would have expected that to work, but if you then move the .exe to a new location (so it is no longer co-located with your jre6 folder) you get the This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted error when you try to run the application...

我一整天都在玩这个,但我无法让 Launch4J 将 JRE 包含在 .exe 文件中.在我看来真的很糟糕,因为他们的文档似乎根本没有提到这个问题.

I've been playing around with this all day and there was no way I could get Launch4J to include the JRE in the .exe file. Really poor in my opinion, as their documentation does not seem to allude to this issue at all.

所以我要解决的是使用Inno Setup Compiler (ISC).此应用程序用于将您的 .exe 包装为 Windows 安装程序文件.所以我在 ISC 脚本中添加了一个设置,用于将 JRE 复制到安装程序包中.我添加到脚本中的行(在 [Files] 部分)是:

So what I did to solve was to use Inno Setup Compiler (ISC). This app is used to wrap your .exe as a Windows Installer file. So I added a setting to the ISC script that copies the JRE into the installer package. The line I added to the script (in the [Files] section) was:

Source: "M:NetbeansMyAppjre6*"; DestDir: "{app}jre6"; Flags: recursesubdirs createallsubdirs

...一些解决方法,但它确实成功了.

...a bit of workaround, but it did the trick.

重复以上所有步骤,你应该已经排序了.

Repeat all the above steps, and you should be sorted.

这篇关于如何将 JRE 捆绑到 Java 应用程序的 EXE 中?Launch4j 说“运行时丢失或损坏".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆