Penchant
Penchant

Reputation: 1165

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

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?

Upvotes: 13

Views: 12734

Answers (3)

eniel.rod
eniel.rod

Reputation: 855

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.

Upvotes: 0

user93202
user93202

Reputation:

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

Upvotes: 7

Maurice Perry
Maurice Perry

Reputation: 32831

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.

Upvotes: 1

Related Questions