How to bundle a JRE with Launch4j?

PortabilityExeJavaLaunch4j

Portability Problem Overview


I have Launch4J on my computer and it's a great program. One of its features I'm interested in is the ability to bundle a JRE in the general .EXE file. However, I can't find any documentation that describes how to go about doing this.

How do I bundle a JRE with the EXE? Plus, where do I get a compact, portable JRE to run? The download links on Oracle are for the installer packages.

Portability Solutions


Solution 1 - Portability

After some attempts i finally get a workaround to bundle the jre in my application:

I package my app as a zip file with the following folders inside:

containerFolder
|- jre
      |-bin (in bin there is java.exe)
      |-lib
|- cfg (to save the user configuration, but it's not needed)
|- bin (my application with the .exe and the .jar and all the other stuff)

In the xml file of launch4j i configure the jre like this:

<jre>
    <path>../jre</path>
    <opt>-DgvSIG.confDir=../cfg</opt>
</jre>

The trick here is that the path is not to the java.exe file. The path to the jre is relative to the position of the .exe and it should point to one folder before the java.exe file

The jre folder i'm using is just a copy&paste from the jre folder installed on a windows system.

Solution 2 - Portability

I did the following and it worked for me using ver Launch4j 3.11:

  1. Created a new folder for my application (called for example MyApp).

  2. Copied the jar file from the java project dist folder to the MyApp along with the lib folder.

  3. Created a folder called jre in my application folder MyApp so now MyApp folder contains:

    • MyApp.jar
    • lib <- this has the libraries needed by my java app.
    • jre
  4. Copied the bin and lib folders from java jre folder (C:\Program Files (x86)\Java\jre7) to MyApp\jre

  5. In the Launch4j having set all the required options, then set the Bundled JRE path to "jre"

    Launch4j JRE options

  6. Make sure that in the search options "Only use private JDK runtimes" is selected.

Solution 3 - Portability

The same problem like you mate. No worries now. Its all solve with the maximum depth to solve future solution. Solution how you can bundle your JRE for your jar without the need that the user has to install java or not. Your java application will run.

  1. Copy lib and bin folder from your JRE folder to your project dist folder

jar to exe conversion

  1. open launch4j and enter the following setting. enter image description here

The trick is you need to give the full path to the including javaw.exe.

Enjoy!!!!

Solution 4 - Portability

I have just done this. Above clearly describe the method for bundling jre.

Here, I just share an experience that I have struggled. If you want to create an installer exe after created wrapper exe by launch4j, pay attention to the file path for launch4j and jre. This is my path I used to solve my issues:

launch4j, bin/jre, resources/bin/jre.

launch4j, bin, and resources are at same level.

Solution 5 - Portability

The jre can usually be found in your SDK folder. Yes the links online are installers, but once it installs, the JRE is now located on your local disk. Mine is located in

${jdk folder}\jre

The parts that you don't need from the JRE could probably be removed manually if you really wanted (I'm not sure whats available online).

Solution 6 - Portability

A working example of using Launch4J to bundle a Java application with a specific JRE can be found at https://github.com/vZome/vzome/blob/master/desktop/platform/windows/README.md. This particular distribution is configured to require vZome to use the bundled JRE rather than any JRE found on the target platform.

Hope this helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCodeBunnyView Question on Stackoverflow
Solution 1 - PortabilityFrancisco PugaView Answer on Stackoverflow
Solution 2 - PortabilityAhmed AwadView Answer on Stackoverflow
Solution 3 - PortabilityDaniel AdenewView Answer on Stackoverflow
Solution 4 - PortabilityMichelleView Answer on Stackoverflow
Solution 5 - PortabilityhbhakhraView Answer on Stackoverflow
Solution 6 - PortabilityDavidView Answer on Stackoverflow