I have a JavaFX project that I would want to compile to a jar such that JRE 8 and above are able to run the jar. I am using Intellij IDEA 2017 CE, running on a Mac, using JDK 9.0.1 as my project SDK.
The project compiles fine for the following gradle settings:
sourceCompatibility = 1.9
targetCompatibility = 1.9
However, when I tweak the target compatibility to 1.8
:
sourceCompatibility = 1.9
targetCompatibility = 1.8
It shows a stream of errors relating to a missing JavaFX library:
Error:(1, 26) java: package javafx.application does not exist
Error:(2, 23) java: package javafx.geometry does not exist
Error:(3, 23) java: package javafx.geometry does not exist
Error:(4, 20) java: package javafx.scene does not exist
Error:(5, 28) java: package javafx.scene.control does not exist
...
I looked at other stackoverflow answers to see why this is happening such as:
- JavaFX comes with JDK 8? Says JavaFX is bundled with JDK 1.8 but I am using JDK 1.9.
- JavaFX and OpenJDK Says OpenJDK has JavaFX, but I am not using OpenJDK
- cannot resolve symbol javafx.application in IntelliJ Idea IDE Says OpenJDK does not have JavaFX (what?), but I am not using OpenJDK
I have also tried to invalidate the caches before building the project but to no avail.
How do I compile to JRE 8 with my JDK?