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!
the second command that DomQ posted was incorrect:
brew tap bell-sw/liberica
brew install --cask liberica-jdk15-full
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:
My experience is that homebrew-liberica just works:
brew tap bell-sw/liberica
brew cask install liberica-jdk15-full
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 (ie, 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.