How can you package an executable jar with a portable JRE?
Asked Answered
Y

3

13

I want to be able to distribute by executable JAR without having to make the user upgrade to the latest version of the JRE. How can I package a JRE into the JAR so that they can run the jar with no JRE installed on their system?

Yanina answered 20/3, 2009 at 3:16 Comment(1)
For windows, jar files are executable or not is mainly depend on the system setting.Arondell
F
7

Put Java Portable in a sub-directory and launch your jar using a batch/bash script or Launch4j.

Forsberg answered 3/8, 2010 at 5:23 Comment(0)
J
1

As you need a jre to execute a jar, I'm afraid this is not possible.

I have once used izpack together with launch4j to make a Windows EXE that would install a jre with my application.

Jauregui answered 20/3, 2009 at 6:33 Comment(0)
G
0

Ten years later I ran into the same problem, and after several days looking, apparently there is still no solution, this is the best thing I have found:

Bundle Java (the JRE) and Launch a Java App with 7zip SFX: Convert Java Apps to an Executable https://mark.koli.ch/bundle-java-the-jre-and-launch-a-java-app-with-7zip-sfx

Edit

I found another way to do it, based on Inno Setup and NetBeans, it often appears as a result of searches about converting jar to exe. Everything is done using Native Packaging in NetBeans IDE.

The result is a standalone .exe installer (YourProjectName.exe) that creates a folder in AppData\Local\YourProjectName. In that folder you will find the launcher, which is an .exe, and also all the necessary files to run the software without installing Java.

You should use exactly the same tools versions that says in the article, otherwise it does not work, at least not for me. The other thing that is not clear is that your project must be a Java with Ant proyect, at least I did not find how to do it with Gradle or Maven.

Also, I had to install an old i586 version of Java (I tried JDK 1.8 i586 and it worked) because JDK 13 causes errors (missing dll's) when trying to run the software. Although I only tried with JDK 13 x64, maybe architecture is the problem and not the version. Whatever, similar happened to NetBeans 11, the .exe launcher did not work, however when locating and executing the .jar it did work. So I ended up using NetBeans 8.

Golter answered 2/10, 2019 at 6:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.