How to bundle a JRE with Launch4j?

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.


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.