Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundle a JRE into an exe using Launch4J

Tags:

java

launch4j

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.

like image 532
Pranav Avatar asked Apr 23 '15 12:04

Pranav


People also ask

What is bundled JRE?

Bundling a JRE, basically means that your application includes its own JRE, that gets installed, along with your application; typically within the same folder (Windows) or within the app bundle (Mac).


1 Answers

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.

like image 62
THelper Avatar answered Oct 17 '22 14:10

THelper