2

Is there any javafx/OpenJFX dependency which can be used directly in the pom file so that it works with OpenJDK 8? Or any workaround (without installing anything) which works with OpenJDK 8?

I have gone through a lot of similar questions on SO, but the solution to use JFX/OpenFX with OpenJDK 8 is either to install the openjfx package in Ubuntu OR use Oracle JDK 8. Unfortunately I cannot do both. I am using OpenJDK 8 and need to use javafx/OpenJFX within my swing application. The OpenJDK does not contain jfxrt.jar in its ext folder (as in case of Oracle JDK 8), and the versions of OpenJFX start from Java 9/10. And on trying to compile I get class file has wrong version 54.0, should be 52.0 which is expected as it is build with Java 10

Any leads would be really helpful. Thanks!

I have already gone through the below links

Why is JavaFX is not included in OpenJDK 8 on Ubuntu Wily (15.10)?

"class file has wrong version 54.0, should be 52.0" while trying to build JavaFX application

"class file has wrong version 54.0, should be 52.0" while compiling javaFX project

How to find out JavaFX version

Pratik Kumawat
  • 146
  • 2
  • 14

2 Answers2

2

Is there any javafx/OpenJFX dependency which can be used directly in the pom file so that it works with OpenJDK 8?

AFAIK, no. There are org.openjfx artifacts for OpenJFX 11 onwards, but they won't work with Java 8. (The class file version will be wrong.)

Or any workaround (without installing anything) which works with OpenJDK 8?

I think you will need to build your own copy of OpenJFX from source, and (touch wood) "package it" with your application1.

(The following is purely based on reading the OpenJFX build instructions. I have not tried this out.)


So if you want to build a stand-alone OpenJFX 8 for use with OpenJDK 8, then you should try the following build instructions on the OpenJFX wiki:

The result of the build is (apparently) a ZIP file that is designed to be "overlayed" onto a JRE installation.

You may be able to repackage that into JARs and native libraries that you can include in your application.


For OpenJFX 9 and later, the build instructions are here:

Apparently, for N >= 9, OpenJFX version N is supposed to be supported for OpenJDK N and OpenJDK N - 1. So if that is accurate, you should be able to build OpenJFX 9 for OpenJDK 8. On the other hand, the build instructions talk about generating modules, and module support is only available in Java 9 and later. However it is still worth a try (IMO).


1 - Options include 1) creating a custom Debian package(s) (or RPMs) ... analogous to the existing Ubuntu packages, 2) incorporating the relevant classes and native libraries into your application JAR, or 3) adding them to your applications classpath and library load path. You may need to experiment.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
2

Why don't you just use, e.g., https://bell-sw.com/pages/downloads/#/java-8-lts and download the full Java version (not standard). It should already contain JavaFX and is one of the many OpenJDK 8 versions floating arround.

mipa
  • 10,369
  • 2
  • 16
  • 35
  • 1
    Well, which JDK to use is not in my control. It is decided at organization level and we only have the option to use that pearticular version of OpenJDK (openjdk-1.8.0.272) – Pratik Kumawat Apr 15 '21 at 12:11
  • "Liberica Full JDK 8u282+8 x86 64 bit for Linux" is one instance of OpenJDK. Who told you that you have to pick a specific provider (which you did not mention in your post anyway) – mipa Apr 15 '21 at 20:03
  • That "one instance" of OpenJDK is not available in my system, and I cannot install it. If you know of a way to get this running via OpenJDK 8, it would be helpful. – Pratik Kumawat Apr 16 '21 at 08:10
  • What are you actually talking about? You have to distinguish between the open sources of OpenJDK and the various distributions built from these sources by different vendors. If you say "get this running via OpenJDK 8" this sentence is meaningless because it does not specify a distribution. Liberica, Zulu, Adoptium,... are all OpenJDKs and satisfy your criteria. – mipa Apr 16 '21 at 09:48