1

I wish to package both my current system's JRE with a Java (JAR) application that I have created. On Mac I can simply create an app bundle and write a simple script to wire the two together. On Windows I am having trouble finding such a simple solution.

I tried launch4j, but to the best of my knowledge this does not let me package the JRE inside the executable; it must remain as a relative file.

I tried exe4j, but this also does not let me package the JRE within the exe.

My project does not use modules, so unclear how I can incorporate jpackage.

I want to distribute the file (as a portable non-installed app) to people working within my company. They are mostly somewhat computer illiterate, and will be scared off by seeing TWO files (one exe, one JRE).

I also do not want to deal with the headache of asking them to install a java runtime themselves, and end up with everyone having some different runtime. Simply, it is much easier for me to package the JRE with the Jar together as a single file and deliver to the end-user. We are doing this with our mac distributions, and everyone is happy.

  • 1
    [How do I bundle a JRE into an EXE for a Java Application? Launch4j says "runtime is missing or corrupted."](https://stackoverflow.com/questions/13996547/how-do-i-bundle-a-jre-into-an-exe-for-a-java-application-launch4j-says-runtime) (read all the answers); maybe [libgdx/packr](https://github.com/libgdx/packr); [How To Bundle A Java App As An Windows Executable EXE (.jar to .exe)](https://robbamforth.wordpress.com/2016/01/29/java-how-to-bundle-a-java-app-as-an-windows-executable-exe-jar-to-exe-6/) – MadProgrammer May 06 '22 at 00:16
  • 1
    Remember, a Mac App bundle is nothing more then a "special" directory, so the JVM and executable are "bundled" into that directory, so for launch4j, you could have your JVM and executed stored in the same directory as each other and then use some kind of installer to "bundle" them into a single package (which is then installed on the system). Even if you end up with a "fully bundled" exe, the JVM will still need to be extracted at runtime, which might slow (at least the first) execution – MadProgrammer May 06 '22 at 00:18
  • The only workable solution I have found from that link above is the Bat To Exe solution. This works, but can only work if I have it extract to the current directory every run. Not ideal. Still nothing quite as elegant as a Mac Bundle that I can find. – Andrew Hamilton May 06 '22 at 00:46
  • 1
    What about Java 14+ `jpackage`? See https://docs.oracle.com/en/java/javase/14/docs/specs/man/jpackage.html – Stephen C May 06 '22 at 01:09
  • I used exe4j way back years ago (I think) and we bundled a JRE with the it (via an installer), this work well when I was using it – MadProgrammer May 06 '22 at 01:14
  • exe4j only lets me package jar files, and not the JRE. I don't want to install software on to the end-users computer, I want it to remain portable. As for jpackage, not sure if I can use it, I do not use modules in my project. Basically, I need the whole JRE. – Andrew Hamilton May 06 '22 at 01:36
  • You can supply the JRE in a separate folder alongside the exe (for example inside a folder named "Application Name.app" which will double as the executable for Mac PC's and contain all the application data, resources, JRE and the Mac files required for launch. – sorifiend May 06 '22 at 01:39
  • If you insist on having a single file, then as mentioned above, one option is some native code or a launcher app that will self extract the JRE to a temporary location before running your main application – sorifiend May 06 '22 at 01:40
  • Hi @sorifiend. This question is for Windows computers, not mac! I already have a mac solution that works great. As for your launcher app idea, I am currently using a program "BatToExe" which packs my JAR and JRE in to an executable backed with a batch file. It is similar to what I have done on mac, but the downside here is the long startup-time, as it extracts the JRE. – Andrew Hamilton May 06 '22 at 01:41
  • Yes, it was just an example, stating that you should have a data folder alongside the exe, and that you could supply the same two things "yourApp.exe" and "yourApp.app" to all windows/mac users and it would work on both (Mac users click the .app folder because mac recognises it, and windows users click the exe because windows recognises it). – sorifiend May 06 '22 at 01:43
  • If you’re okay with a directory tree like a Mac bundle, you may want to create and distribute a jlink’d image. See https://stackoverflow.com/questions/53453212/how-to-deploy-a-javafx-11-desktop-application-with-a-jre. – VGR May 06 '22 at 16:33

0 Answers0