Installing JavaFX 15 on Mac
Solution 1
the second command that DomQ posted was incorrect:
brew tap bell-sw/liberica
brew install --cask liberica-jdk15-full
Solution 2
My experience is that homebrew-liberica just works:
brew tap bell-sw/liberica
brew cask install liberica-jdk15-full
Solution 3
You can either use the terminal or set up a launch configuration in VS Code.
To use the terminal, you can either install Liberica or download the latest JavaFX from Gluon (or the Early-Access build). To compile your *.java
file, make sure to specify and set the --module-path
and the -cp
as command arguments for javac
on the CLI.
For example, if you downloaded the JavaFX SDK to your ~/Downloads
directory (i.e., you downloaded JavaFX 16 and extracted it in your ordinary Downloads folder), then you will run something like
javac --module-path "$(eval echo ~$USER)/Downloads/javafx-sdk-16/lib/*" -cp "$(eval echo ~$USER)/Downloads/javafx-sdk-16/lib/*" -d . JavaFXThing.java
Then, in order to run your program, you'll use:
java --module-path "$(eval echo ~$USER)/Downloads/javafx-sdk-16/lib" --add-modules javafx.controls,javafx.fxml JavaFXThing
Check what modules you need to specify for the --add-modules
parameter here: API documentation for JavaFX 15
Here is a sample launch.json
to enable debug launching in VS Code:
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch JavaFX Class",
"request": "launch",
"vmArgs": "--module-path \"/Users/kevinmou/Downloads/javafx-sdk-16/lib\" --add-modules javafx.controls,javafx.fxml",
"mainClass": "${file}"
}
]
}
For JDK, I recommend using Liberica with Homebrew, since it is easy to keep up-to-date (yay, Homebrew! 🍻) and Liberica takes care of the paths and environment variables (including JavaFX). To install, in a shell, try:
brew tap bell-sw/liberica
brew cask install liberica-jdk15-full
Then, to update
brew update && brew cask upgrade
Solution 4
You need to take care with environment variables mixing with GUI applications on macOS. Setting PATH_TO_FX in the terminal likely didn't set the value for the IntelliJ IDE. You will note that the instructions at https://openjfx.io/openjfx-docs/#IDE-Intellij explicitly mention setting that value within the IDE, not from the Terminal.
I strongly suggest using Gradle or Maven with the code samples given at https://OpenJFX.io/ as a starting point. Confirm that the builds work from the command line before debugging what the IDE might be doing differently.
You can also install a JDK that includes the JavaFX modules. A few OpenJDK providers have such builds. For example:
- BellSoft produces a "Full JDK" Liberica JDK install, https://bell-sw.com/pages/downloads/
- Azul produces a "JDK FX" java package for Zulu builds of OpenJDK, https://www.azul.com/downloads/zulu-community/
Fernando Edelstein
Updated on June 04, 2022Comments
-
Fernando Edelstein almost 2 years
I'm trying to install JavaFX 15 on my Mac but I'm stuck.
Running MacOS Mojave 10.14.6
I've already installed Java 13 JDK and set the Home folder, downloaded the JavaFX SDK from https://gluonhq.com/products/javafx/ , I've already ran the code "export PATH_TO_FX=/Users/.../javafx-sdk-15/lib" in Mac terminal.
I'm using IntelliJ for programming and I tried to set the path at Project Structure - Libraries
but apps won't compile.
Could somebody help me? Thanks a lot in advance!
-
Slaw about 4 yearsNote that the latest release of JavaFX is version 14, which was released within the last month. JavaFX 15 is currently early-access (and will be for the next 5-6 months).
-
-
user674669 over 2 yearsOn Homebrew 3.2.8, I had to use: brew install --cask liberica-jdk8-full