6

I'm attempting to bundle the JRE into my exe using launch4j.

My folder structure is as follows-

|- test
    |- jre(copied from my windows installation of jre)
        |-bin
        |-lib
    |- jretest.jar (the jar file I am using to create my exe)
    |- jretest.exe (the output exe file)

In Launch4j, I have set the Bundled JRE Path as jre.

The exe works fine so far.

However, when i copy my exe file elsewhere and run it, I get the error message This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted.

I have searched on SO and found the following questions but couldn't get my application to work with the suggestions given there.

How do I bundle a JRE into an EXE for a Java Application? Launch4j says "runtime is missing or corrupted."

How to bundle a JRE with Launch4j?

Any idea what could be going wrong here with a jre bundled in it?

How can I make an independent exe ?

I do not want to make an installer for my application but just intend to run it.

Any help would be greatly appreciated.

Community
  • 1
  • 1
Pranav
  • 323
  • 1
  • 3
  • 16
  • Have you tried running the Jar on this JRE using cmd? Its pretty straight foward on lauch4j, just type the name of the JRE folder and see that it is on the same folder as the jar/exe. Maybe your JRE is corrupted. – Renatols Apr 23 '15 at 12:45
  • Initial problem solved(I assume something wrong with my jre. I deleted and copied it again and it began to work). The exe works perfectly fine when it is in the same folder as the original jar file. But when I copy the exe elsewhere, it ceases to work(shows error that jre is missing or corrupt). How can I make the exe completely independent? – Pranav Apr 23 '15 at 18:03
  • What do you mean by independent? If you want to be able to run the .exe no matter where it is, you can specify an absolute path instead of a relative one, like C:\Java\JRE for example. – Renatols Apr 23 '15 at 18:23
  • But that wont work on another computer. How can I put the jre inside the exe so that it works on any computer which doesnt have a jre installed? – Pranav Apr 24 '15 at 03:44
  • 1
    I really dont think you can do it, not with Launch4j or any onther. Besides, your exe would have at least 100mb and thats not a good thing at all. Your best bet is to use Launch4j to bundle the JRE and a software like Inno Setup to create an installer. – Renatols Apr 24 '15 at 11:58

1 Answers1

7

With launch4j it's not possible to put the JRE inside an exe. The 'bundle' option of launch4j simply means that you distribute your exe together with a JRE, so alongside it. You can do this by adding the following option to your config xml file.

<jre>
    <path>.....</path> 
</jre>

It's important that you specify the path to the JRE relative to your executable, otherwise it won't work if you move the exe to another location (or to another computer). The error message you got is because you didn't move or copy the JRE together with your exe, so the executable can't find the JRE anymore.

Alternatively if you don't use the bundle option, launch4j will try to use a system JRE and if it cannot find one redirect users to the Oracle JRE download page. If this is not what you want, and you really want a single exe for distribution then your only other option is to use an installer like NSIS or Inno Setup.

THelper
  • 15,333
  • 6
  • 64
  • 104
  • 4
    "The 'bundle' option of launch4j simply means that you distribute your exe together with a JRE, so alongside it." So basically it's like the "provided" scope of Maven... That should be made clear in the doc, given the number of people (me included) that try in vain to actually bundle the JRE inside the exe! – Olivier Gérardin Jun 08 '20 at 21:27