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

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

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

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

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

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

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.

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:\Netbeans\MyApp\jre6\*"; 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.


the easy method to package jre to exe that lanch4j packaged is use wrap.

warp-packer --arch windows-x64 --input_dir mycrt --exec run.bat --output single.exe

and then stop cmd windows when launch exe.

editbin /subsystem:windows

warp: https://github.com/dgiagio/warp

editbin: installed by VS

Demo:

enter image description here

enter image description here