Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bundle a JRE with Launch4j?

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.

like image 213
CodeBunny Avatar asked Aug 15 '11 21:08

CodeBunny


People also ask

How do I create a JRE bundle?

You can create install4j JRE bundles from installed JREs by invoking Project->Create a JRE Bundle from the main menu or by using the createbundle command line utility. It is not possible to directly convert a ZIP with a JRE or an archive downloaded from the Oracle web site into a JRE bundle that is usable by install4j.

What is a JRE bundle?

Here you can select a JRE to be bundled with your application. The JRE files will be excluded from the builds if this option is not being used. This is a very useful option for a Java application, which allows you to reduce the installation requirements of your package.


2 Answers

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.

like image 98
Francisco Puga Avatar answered Sep 16 '22 11:09

Francisco Puga


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.
like image 28
Ahmed Awad Avatar answered Sep 18 '22 11:09

Ahmed Awad