Environment:
The problem:
I know, that the JDK 1.8 is supposed to come with JavaFX included. However, for OpenJDK 1.8 this, somehow, seems not to be the case (without the Maven dependencies, IntelliJ doesn't accept import javafx.application.Application;
nor any other JFX imports).
For this reason, I am trying to include it as a Maven dependency. If I use:
<!-- JavaFX -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
.
.
.
I get the following error message:
Error:(3, 26) java: cannot access javafx.application.Application
bad class file: /C:/Users/kaspa/.m2/repository/org/openjfx/javafx-
graphics/11/javafx-graphics-11-win.jar!/javafx/application/Application.class
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.
Using <version>12</version>
yields [...]wrong version 55.0, should be 52.0[...]
.
The lowest <version>
, inside the Maven <dependency>
, I am able to use seems to bo 11.
The Question:
pom.xml
to make my application compile and run?First, a bit of background. From Java 8 to Java 10, the Oracle JDK used to come with JavaFX. But, even in these versions, JavaFX is not part of the OpenJDK. From Java 11, JavaFx is also not part of the Oracle JDK (as was the case with OpenJDK).
So, What are you doing wrong?
You are trying to run JavaFX 11 and 12 with JDK 8. This is not possible.
What can you do?
Get the openjfx 8. You can either build them from source or install it through sudo-apt on Ubuntu.
Is JavaFX 8 available as Maven dependency?
Not that I am aware of!
My advice.. Use Oracle JDK if you want to use Java8 or upgrade to Java 11 and use openJFX as Maven dependency.