Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.
is it possible to embed the JRE inside the EXE ? and if yes how ?
This is not directly possible but there's a simple workaround. The documentation doesn't explain it clearly, but the diagram on the home page gives a hint when it mentions "Installer created by an external installer program". Here's what you have to do.
1. Copy your desired JRE (the whole thing from the "jre" folder of some JDK/JRE installation) into a subdirectory below your Launch4j output executable. Let's call this subdirectory "jre" for simplicity.
2. Set the JRE path in the Launch4j configuration to the name of that subdirectory, "jre" in this example. Use a RELATIVE path.
3. Now when you deploy your program, you must wrap the Launch4j-created executable AND the jre folder in a zip or setup package so both get deployed to the target machine.
4. When the executable starts, it will search for its JRE in that relative path specified in the Launch4j configuration. Now it can run on a system that doesn't have a JRE installed. Phew!
Same procedure applies when you want to package arbitrary libraries with your main application JAR: you need to manually package & deploy them alongside the Launch4j-created executable. Launch4j does exactly one thing, and that's providing a launcher for your main JAR. Basically the same thing as a simple batch file launcher, plus some Windows integration extras. Launch4j's "big" feature is to automatically search for matching JREs but if you package your JRE anyway that doesn't apply.
This is indeed a workaround and it works. But it burdons my user with an extra step: the unzipping of the zip containing the jre and the l4j produced exe. More to explain, more to go wrong.
Would it be possible to just put the jre dir in the jar that I am building the l4j exe from, just snuggly next to my classes and then have the exe bit of launch4j exe unzip this jre first to some tmp place and then start that jre with my classes.
That would enable my users to do one download and one double click.
Is unzipping before running java a big deal? That has to be done in native code of course.
Just an idea.
If you're fine with extracting to a permanent location (such as c:\Program Files) you could use any number of installer utilities, e.g. InnoSetup (http://www.jrsoftware.org/isinfo.php), to wrap your launch4j executable plus the JRE and all other JARs.
Extracting to a temporary location and then deleting those files after the program closes is trickier. I don't think InnoSetup can do that. You might be able to script something with a general purpose packer such as 7-zip or WinRAR.
In general I think that would pollute my users machine. I will check out InnoSetup and see if I can find a way…. thanks Chris.
Still I think it would be a logical, valuable and simple addition to launch4j.