How to use JFX/OpenFX with OpenJDK 8 - java

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

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:
Building OpenJFX 8u
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:
Building OpenJFX
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.

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.

Related

How to Use Java 8 settings to build project in eclipse 4.18(2020-12)

*Due to some project requirements I "have" to use eclipse 4.18 (2020-12) which uses Java 11 by default and is mandatory to start.
But my entire project is/was written in Java 1.7 earlier. Now , in my mac i have both java 1.8 and 11 installed also my eclipse settings are such shown below.
I have made sure removed all java 11 references in my eclipse and made the project and workspace configure to take the 1.8 jdk and run at 1.7 compiler level.*
but when i run ,project -->clean-->build, i run into the JaxB missing in java 11 ( in java 11 JAXB was removed and my project uses jaxB extensively) This is known.
So i am wondering what am i missing that my projects are still building my project with java 11 and not java 1.7 (using jdk 1.8 configured).
Please help.. stuck on this since some days.
machome
Eclipse Compiler setting-1
Eclipse Setting Execution Envs
Eclipse installed JRE's
Eclipse Project specific setting
Java 11 JaxB error
If Eclipse itself is being run with Java 11, and you have a plug-in installed that has not been properly update to work under Java 11, as it appears, you will need an updated version of that plug-in. Update to the latest "oracle design studio", and if you still see this problem, contact Oracle support.
The latest Eclipse may require Java 11 to run, but it's simple to set up Eclipse projects that use older Java versions. Don't mess with the Java version it uses to start up, as long as that is a proper Java 11 version.
As one commenter mentions, you'll have to have a particular Java distribution configured in "Installed JREs->Execution Environments", and then you'll have to have the project configured to use that Java version symbol, like "JavaSE-1.7".

OpenJDK 8 with JavaFX

I have installed OpenJDK 8 and want to create a JavaFX app. Since JavaFX is not included in OpenJDK 8, I tried to install OpenJFX via maven:
downloaded org.openjfx:javafx-controls:11 and org.openjfx:javafx-fxml:11. It seems fine, the libs are resolved.
But when I execute the program, I get the following error message:
class file has wrong version 54.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
So I think I have the wrong version of the libs, since Java 8 is class file version 52. Is there a OpenJFX lib available for Java 8. Or did I miss something else?

JavaFX only run with JDK

My JavaFX Desktop program only run with JDK 1.8 installed, doesnt run with JRE 1.8.
Any JavaFX Application should run with JRE?
If NO, How can I find why JDK is needed?
This is because JavaFX runtime is not packaged into some distributions of JRE. As far as I know JavaFX will be in all distributions only when JDK 9 is released. Till then, it is safer to install JDK instead of JRE, or you can include jfxrt.jar when you export your project into JAR file.
Per Oracle's documentation, the JavaFX SDK and Runtime (jfxrt.jar) are included in the Java JDK, beginning with Java SE 7 Update 2. As long as the application was compiled with this version or later, it should run JavaFX.
Also per their site, the JavaFX APIs are fully integrated with the Java SE Runtime Environment (JRE) and the Java Development Kit (JDK).
The specific location where you should find jfxrt.jar in both the JDK and JRE is:
For Java 7, under jre\lib
For Java 8, under jre\lib\ext
Additional info can be found at Oracle's various JavaFX resources such as here and here - though the latter was created for JavaFX 2, so may not be entirely compatible with the latest version of JavaFX.

Create Jar Compatible With Java 7 With IntelliJ Using JDK8

I am using JDK8 on my normal desktop and I have a separate linux box that I am trying to run the Java program on.
The problem I'm running into is that the linux box is running jdk7, so the computer has JRE7 basically that it is running off of. My question is, is it possible to create a jar file in JDK8 that will be compatible with java 7?
I'm using IntelliJ to compile. I tried to compile in 1.7, but it gave an error when I did end up trying to do it. I compile it here:
In 1.8 it works fine to compile, but when I try to compile in 1.7 it doesn't work.
I know the short answer is to update the linux to JRE 8. But I am curious, is there a way to make it backwards compatible? Or is the other answer to simply install JDK7 on the desktop in order for it to run on the linux box using JRE7?
Java programs built with JDK 8 will only run on machines running JRE 8 (or higher).
I found this when trying to compile classes on my local Linux machine (using JDK 8) and deploying to a remote server running JRE 7. The classes just wouldn't work (like you're finding).
If you want to use JRE 8 on linux, I recommend using the oracle-java8-installer package from webupd8team. Installation instructions found here (assuming Debian based distro).
If you want to compile to JDK 7, it's not good enough to only have JDK 8 installed and pick to compile 1.7. You need JDK 7 installed to and restage your project to use JDK 7.
The thing you have to remember is that the difference between JRE/JDK versions is not just the extra features developers can use (e.g Lambda functions) but it's also that the JRE itself is improved (efficiency, garbage collection, etc.).
As a extreme example: If you wrote code that only used JDK 1 features but compiled it using JDK 8, it wouldn't run on a machine running JRE 1 because the Java classes had been compiled with JRE 8 in mind.
Do note though, that if you're Java Code uses only features from JDK 7 or 6 etc., you might think it good practice to compile using the minimum JDK required to allow for compatibility with more machines. Well...you'd have that compatibility but at a cost of using inefficient, out of date, possibly vulnerable compiled classes (At little extreme, but you get my point).
Are you using any new Java 8 features? Because if you are, this means you cannot build the project against the JRE7.
If you are not using any Java 8 features, you can build to Java 7 most easily by downloading the JDK7 and switching the project to use that instead of the JDK8.
You should also set project language level to 1.7 (and module language level(s) as well, if they're different). It's done in Project Structure settings dialog. After that the project should compile.
Note that you shouldn't use any of the APIs that appeared in 1.8, but such usages will most likely be highlighted in the editor.

Linux (centos), openjdk 8, openjfx and netbeans 8

So I installed at centos 6.4 openjdk 8, netbeans 8 and build openjfx. The only thing I can't uderstand is how to make netbeans work with built openjfx sdk. As openjdx sdk is in folder /temp while jdk is in /usr/lib/jvm/java-8... I can't undertand how to add openjfx to netbeans as everywhere people say that jfx is already in jdk.
So, what now should I do to make all these work together?
It's easiest just to use the Oracle JDK if you can do that. You could possibly hack something together by installing the Oracle JDK, seeing where in the JavaFX code is placed in the Oracle JDK and copying the OpenJFX build artifacts you created to similar locations in the OpenJDK, then pointing your NetBeans at the integrated OpenJDK/OpenJFX install. Seems a lot of a work for a development environment though when you could just use Oracle JDK and it would just work out of the box. You could always switch to OpenJDK/OpenJFX for final packaging for customer delivery once your development is completed.
Ubuntu has binary OpenJFX packages available, so if you could switch to Ubuntu, you should be able to use them (I've never tried it).
I am not aware that anybody has created anything similar for CentOS (this may change in the future). If you stick with CentOS, you would probably need to follow my earlier advice of manually copying JavaFX files into the OpenJDK structure at the locations that NetBeans expects. Usually the files you will need to worry about are the jfxrt.jar file (see What's the location of the JavaFX runtime JAR file, jfxrt.jar, on Linux?) and the associated binary libraries (which must be in the correct location to be found), though there are possibly other files such as property files or javafx swt integration libraries that might be needed for correct function.
See related question:
JavaFX and OpenJDK

Categories