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