简体   繁体   English

使用Launch4J将JRE捆绑到exe中

[英]Bundle a JRE into an exe using Launch4J

I'm attempting to bundle the JRE into my exe using launch4j. 我正在尝试使用launch4j将JRE捆绑到我的exe中。

My folder structure is as follows- 我的文件夹结构如下 -

|- test
    |- jre(copied from my windows installation of jre)
        |-bin
        |-lib
    |- jretest.jar (the jar file I am using to create my exe)
    |- jretest.exe (the output exe file)

In Launch4j, I have set the Bundled JRE Path as jre . 在Launch4j中,我将Bundled JRE Path设置为jre

The exe works fine so far. 到目前为止exe工作正常。

However, when i copy my exe file elsewhere and run it, I get the error message This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted . 但是,当我将我的exe文件复制到别处并运行它时,我收到错误消息This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted

I have searched on SO and found the following questions but couldn't get my application to work with the suggestions given there. 我搜索了SO并发现了以下问题,但无法让我的应用程序使用那里给出的建议。

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

How to bundle a JRE with Launch4j? 如何将JRE与Launch4j捆绑在一起?

Any idea what could be going wrong here with a jre bundled in it? 知道这里捆绑的jre会出现什么问题吗?

How can I make an independent exe ? 我怎样才能创建一个独立的exe?

I do not want to make an installer for my application but just intend to run it. 我不想为我的应用程序制作安装程序,只是打算运行它。

Any help would be greatly appreciated. 任何帮助将不胜感激。

With launch4j it's not possible to put the JRE inside an exe. 使用launch4j,不可能将JRE放在exe中。 The 'bundle' option of launch4j simply means that you distribute your exe together with a JRE, so alongside it. launch4j的'bundle'选项只是意味着你将你的exe与JRE一起分发,以及它旁边。 You can do this by adding the following option to your config xml file. 您可以通过在config xml文件中添加以下选项来完成此操作。

<jre>
    <path>.....</path> 
</jre>

It's important that you specify the path to the JRE relative to your executable, otherwise it won't work if you move the exe to another location (or to another computer). 指定JRE相对于可执行文件的路径非常重要,否则如果将exe移动到另一个位置(或另一台计算机),它将无法工作。 The error message you got is because you didn't move or copy the JRE together with your exe, so the executable can't find the JRE anymore. 您收到的错误消息是因为您没有将JRE与您的exe一起移动或复制,因此可执行文件无法再找到JRE。

Alternatively if you don't use the bundle option, launch4j will try to use a system JRE and if it cannot find one redirect users to the Oracle JRE download page. 或者,如果您不使用bundle选项,则launch4j将尝试使用系统JRE,如果找不到一个重定向用户到Oracle JRE下载页面。 If this is not what you want, and you really want a single exe for distribution then your only other option is to use an installer like NSIS or Inno Setup. 如果这不是你想要的,并且你真的想要一个exe分发,那么你唯一的另一个选择是使用像NSIS或Inno Setup这样的安装程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM