Bundle a JRE into an exe using Launch4J

纵然是瞬间 提交于 2019-12-03 20:22:00

问题


I'm attempting to bundle the JRE into my exe using launch4j.

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.

The exe works fine so far.

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.

I have searched on SO and found the following questions but couldn't get my application to work with the suggestions given there.

How do I bundle a JRE into an EXE for a Java Application? Launch4j says "runtime is missing or corrupted."

How to bundle a JRE with Launch4j?

Any idea what could be going wrong here with a jre bundled in it?

How can I make an independent exe ?

I do not want to make an installer for my application but just intend to run it.

Any help would be greatly appreciated.


回答1:


With launch4j it's not possible to put the JRE inside an exe. The 'bundle' option of launch4j simply means that you distribute your exe together with a JRE, so alongside it. You can do this by adding the following option to your config xml file.

<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). 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.

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. 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.



来源:https://stackoverflow.com/questions/29823733/bundle-a-jre-into-an-exe-using-launch4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!