How to bundle a JRE with Launch4j?
Asked Answered
P

7

93

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.

Persistent answered 15/8, 2011 at 21:39 Comment(3)
Launch4j allows you to bundle a JRE with your exe, so alongside it. You can't use it to embed the JRE in your exe.Flagwaving
What does that even mean...Prosody
@Prosody It means that you can ship your program in a folder with your JRE contained, but you can't generate a standalone .exe file using launch4j that automatically includes your JRE. Therefore, you can bundle a JRE with your exe (in the same folder), but you can't embed it into the exe itself. You'll end up distributing a folder to your clients, or you'll end up depending on their system's JRE/JDK.Arette
A
104

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.

Amaurosis answered 28/9, 2011 at 10:50 Comment(8)
That helped me a lot!The docs are not too clear about this... Works like a charm :-)Later
Hi what is this path <path>../jre</path> either it is existing path which is in C://..java folder or a new java JRE installer which is downloaded.Daegal
@RajaReddyPolamReddy is the relative path from your .exe file to the folder where the jre is located within your applicatinAmaurosis
The question asked how to bundle the JRE in the EXE with launch4j. This answer shows how to tell launch4j to use a specific JRE which you have bundled with your EXE, but not inside it. This seems to be the best that can be done with launch4j. (Another answer below shows one way to create an installer which will then install both your EXE and the JRE, but the JRE will not be in the EXE.)Holloman
How do you copy the jre?Topdrawer
At the time this answer was written i was using an Ant script that builds the exe from the launch4j config file, compile my app, and build the zip. The jre was copied in the ant script to a folder prior to zip all the folder.Amaurosis
And what about JDK11 that doesn't come with a JRE?Kling
@Kling this answer links to AdoptOpenJDK which offers JREs for newer versions of Java like Java 11. Alternatively you can learn about and use the jlink tool to build your own JRE.Marvelmarvella
A
22

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.
Aquamarine answered 29/3, 2018 at 9:59 Comment(3)
Does this bundle the jre in with the exe, or do you have to zip it all up and put the .exe with the jre folder when you give it to others to run like in the accepted answer? https://mcmap.net/q/104230/-how-to-bundle-a-jre-with-launch4jRenaldo
No, this doesn't bundle the jre with the exe, the only thing that can be bundled with the exe is your app jar fileAquamarine
Can you please update this for launch4j 3.50 - This does not work any moreCaprine
D
9

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

Dannettedanni answered 3/1, 2018 at 11:1 Comment(1)
Put any file in dist folder making this error during clean and build: Unable to delete file...Bohemia
R
1

The mentioned answers above did not work for me. I am using JDK 20. What I did:

  1. Created my Jar file
  2. Create a folder for the application appFolder
  3. Put the jar file in appFolder
  4. Created a myJdk folder in the appFolder
  5. Put the contents of the JDK on my machine in the myJdk folder in the appFolder
  6. Set the path to the bundled JRE(JDK in my case) to myJdk/bin, which is relative to the appFolder.

A simple folder view:

appFolder
|- myJdk
   |- all contents from my jdk folder, installed on the machine. (The only folder I could remove was the jmods. All the rest were needed)
|- jar file
Raycher answered 17/6, 2023 at 20:23 Comment(0)
H
0

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.

Hydrometallurgy answered 21/6, 2019 at 21:23 Comment(0)
A
-2

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

Ables answered 15/8, 2011 at 21:53 Comment(2)
How do I bundle it into the EXE? I'm trying to package everything in the jar so that I wouldn't have to worry if the user has Java installed. I realize that just having them download java is probably the best idea; however, I'd like to experiment with all of my deployment options.Persistent
@Persistent This is not possible with Launch4j alone, but somebody found another nice solution: mark.koli.ch/…Pushup
F
-2

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.

Fanfare answered 30/7, 2019 at 20:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.