9

Environment:

  • OS: For developing and running the application, both Windows 10 Pro (1809) and Linux (something like Ubuntu or Debian) with OpenJDK 1.8 and Maven installed will be used.
  • JDK: OpenJDK 1.8
  • IDE: IntelliJ Ultimate
  • Build tool Maven (multi-module project, one module uses JavaFX)
  • I'd very much prefer not to use anything with a paid license (even though, for this project, I could probably use the Oracle JDK for free...).

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:

  • Is there something I can add/change to my pom.xml to make my application compile and run?
  • Do I absolutely need to upgrade to OpenJDK 11 or 12?
KasparJohannes
  • 449
  • 2
  • 6
  • 20
  • 1
    You can't run JavaFX 11+ with JDK 8. If you really need to stay on 8, I suggest you use a JDK that has already JavaFX bundled, and there are a few options out there, or you install JavaFX 8 from OpenJFX (but not with Maven). – José Pereda May 27 '19 at 22:23
  • 1
    I´d like to know what it is that keeps you from just updating to the current release of JDK which is 12. I mean this as a serious question not as a criticism. – mipa May 28 '19 at 08:00
  • @mipa: Me personally? Nothing! I'm very open to new versions/technology and I update everything I can, even though I am aware that this in most cases is going to cause problems and consume man hours. – KasparJohannes May 28 '19 at 20:05

1 Answers1

4

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.

  • 1
    I downloaded and installed Oracle JDK 8 but I still get the javafx.application, etc. does not exist errors. Any other suggestions? – mybodycravesbutterygoodness Nov 22 '19 at 21:14
  • 1
    heroku uses OpenJDK 8 if you set your project to use Java 8. So just using Oracle JDK 8 is not an option. There must be a maven dependency somewhere that includes javafx on a java 8 level. For heroku, another option is to use buildpacks to include javafx 8. but that hasn't been successful for me yet. – bautrey Mar 15 '20 at 15:10
  • @gopala-krishna-char - can you please explain how this will work with project using OpenJDK8? "Get the openjfx 8. You can either build them from source or install it through sudo-apt on Ubuntu." – Pratik Kumawat Apr 15 '21 at 06:54