0

After installing both the OpenJDK and the Temurin casks (testing out first one, then the other), I'm still getting errors like these when running a simple example javafx app from the terminal:

Example.java:1: error: package javafx.application does not exist

It seems to me like JavaFX is not included in OpenJDK for macOS, at least the Homebrew versions, but it should be.

The version I'm installing is 17, on both counts.

What can I do to fix this? (I specifically don't want to install Oracle's JDK, to avoid hefty future licensing fees or potential litigation, which Oracle is known for.)

Tin Man
  • 700
  • 8
  • 29
  • 3
    JavaFX is not included in the JDK since Java 9 (with the exception of the Azul JDK, IIRC). You need to include JavaFX on the class path yourself. – Mark Rotteveel Nov 14 '21 at 17:27
  • 2
    Read the [openjfx.io Getting Started documentation](https://openjfx.io/openjfx-docs/). – jewelsea Nov 14 '21 at 17:46
  • A complete, command-line example is cited [here](https://stackoverflow.com/a/69651076/230513). – trashgod Nov 14 '21 at 17:49
  • 1
    @MarkRotteveel Small clarification: JavaFX should be on the module path, not the class path, it can be run from the class path currently, and it works, but [it isn't supported that way](https://stackoverflow.com/questions/67854139/javafx-warning-unsupported-javafx-configuration-classes-were-loaded-from-unna). – jewelsea Nov 15 '21 at 04:02
  • @jewelsea Thanks, I didn't know that (I haven't actually used JavaFX myself). – Mark Rotteveel Nov 15 '21 at 07:24

1 Answers1

5

JavaFX has never been an official part of the Java platform.

For a while, Oracle was bundling the JavaFX libraries with their own Oracle JDK product, but later stopped. Those libraries were a bonus, an extra, not required by the Java specifications.

Keep in mind that several vendors provide Java implementations. At least two of them provide a variant that includes the OpenJFX libraries implementing JavaFX, if that is what you want:

  • ZuluFX by Azul Systems
  • LibericaFX from BellSoft

Last time I looked, both of those products were available for macOS on both Intel Macs and Apple Silicon Macs.

Alternatively, you can bundle the OpenJFX libraries within your app.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
  • Ah, okay, thanks for letting me know. I read somewhere that JavaFX was BACK in JDK, but didn't get that they only meant the Oracle JDK. In any case, I'm including it now via Gradle and it works! :) – Tin Man Nov 15 '21 at 22:51