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

Deadly 提交于 2019-11-27 13:25:57

问题


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?


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/664858/how-can-you-package-an-executable-jar-with-a-portable-jre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!