Search code examples
javamavenjavafxdeploymentjavafx-11

How to run java11 and jfx11 application on jre1.8


I am a computer student and I had during my internship in a company, develop a small java software using JavaFX, maven, and apache.poi.

Info: The application works on Intellij and builds perfectly, my problem concerns the *.jar that I generate once the project is finished.

I first used JDK 14 and JFX14, however at the time of the execution (java –jar xx.jar) I had an error saying that I was compiling the program in JAVA 58 (JAVA 14) and that I was using JRE 52 (JAVA 8).

So I modified the project to compile with JDK 11 and JFX 11, and I now have the same error telling me that I am compiling the program in JAVA 55 (JAVA 11) and that I was using JRE 52 (JAVA 8).

The error comes from the fact that my PC uses jre1.8.0_251 by default.

So I tried to launch the program in this way "path_to_jdk11 \ bin \ java.exe" -jar xxx.jar and it works.

So that's my problem:

The majority of users use the version of JAVA offered on the Oracle site, i.e. jre1.8.0_251 which is the latest version available. Outside my program requires Java 11, which is not deploying on corporate PCs, I imagine. I tried to port my project to java 8 but I have errors with Maven and the module.info.java.

Do you have a tip for deploying the *.jar or deploying it in .exe so that it can run with a user who has jre1.8.0_251?

Respectfully


Solution

  • Don't try to build a fat jar. It won't work with modern Java. Instead build a real installer. This can be done easily with JDK 14+. Just follow this tutorial https://github.com/dlemmermann/JPackageScriptFX which covers everything you need. This uses jpackage from JDK 14 and some other tools from it and also works with non-modularized projects. When you install JDK 14 just make sure you set JAVA_HOME and your PATH correctly so that all the tools find the correct version of Java for building.