How to bundle a JRE with Launch4j?

2019-01-02 15:10发布

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.

5条回答
十年一品温如言
2楼-- · 2019-01-02 15:32

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

查看更多
残风、尘缘若梦
3楼-- · 2019-01-02 15:35

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.
查看更多
萌妹纸的霸气范
4楼-- · 2019-01-02 15:42

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

查看更多
梦醉为红颜
5楼-- · 2019-01-02 15:49

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.

查看更多
牵手、夕阳
6楼-- · 2019-01-02 15:58

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 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. This app is used to wrap your .exe as a Windows Installer file. So I added a setting to 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.

ANSWER TAKEN FROM here..user1617737

查看更多
登录 后发表回答