Embed a JRE in a Windows executable?
Suppose I want to distribute a Java application.
Suppose I want to distribute it as a single executable. I could easily build a .jar with both the application and all its external dependencies in a single file (with some Ant hacking).
Now suppose I want to distribute it as an .exe file on Windows. That's easy enough, given the nice tools out there (such as Launch4j and the likes).
But suppose now that I also don't want to depend on the end user having the right JRE (or any JRE at all for that matter) installed. I want to distribute a JRE with my app, and my app should run on this JRE. It's easy enough to create a Windows installer executable, and embed a folder with all necessary JRE files in it. But then I'm distributing an installer and not a single-file app.
Is there a way to embed both the application, and a JRE, into an .exe file acting as the application launcher (and not as an installer)?
Solution 1:
Try to use Avian and ProGuard toolkits. Avian allows to embed lightweight virtual machine in you app. Linux, MacOS, Windows and iOS are supported. And ProGuard allows you to shrink large jar file to prepare to embed.
Solution 2:
There's a new tool that does this: Packr
https://github.com/libgdx/packr
Solution 3:
Quite a few options around, commercially this is very good:
http://www.excelsior-usa.com/jet.html
There are two key open source options GCJ and VMKit
http://gcc.gnu.org/java/ and http://vmkit.llvm.org/
Other more prolonged paths would include IKVM.NET:
http://www.ikvm.net/
Which is a .NET JVM which can be statically compiled to an EXE