This guide is for setting up JDK, Eclipse, and JavaFX on MacOS. A video showing this process is available here.
Before we start, remember a few important things:
- Use OpenJDK from AdoptOpenJDK instead of JDK from Oracle.
- Use LTS (Long Term Support) version instead of the latest version.
- Remove old version before installing a new one.
JDK
Download OpenJDK 11 (Hotspot) from AdoptOpenJDK. Double click on the downloaded .pkg file and follow the instructions.
Eclipse
Download Eclipse IDE for Java Developers from Eclipse.org. Double click on the downloaded .dmg file, and in the opened window, drag Eclipse to Applications.
JavaFX
Download JavaFX 11 Mac OS X SDK from Gluon.com. Unzip the downloaded .zip file to a local folder. We'll refer to this folder as the JavaFX folder.
To create a JavaFX project in Eclipse, follow the instructions in the [JavaFX and Eclipse: Non-modular Project - IDE] section of Getting Started with JavaFX. The key steps are:
- Create a User Library that includes all the jar files in the JavaFX folder. This step only needs to be done once, while all the other steps need to be done for each project.
- Create a Java Project without module (uncheck the [Create module-info.java file] option)
- Add the User Library created in the first step to the project.
- Run the main class once to create a Run Configuration.
- Add the following to VM Arguments (where /path/to/javafx/lib is the path to the lib folder under the JavaFX folder):
--module-path /path/to/javafx/lib --add-modules javafx.controls,javafx.fxml
- Uncheck the [Use the -XstartOnFirstThread argument when launching with SWT] option. If you missed this step, JavaFX code will run but the window won't show.
Uninstallation
Uninstalling JavaFX is simple - just delete the JavaFX folder. Of course any project references JavaFX won't work after that.
To uninstall Eclipse, go to Finder -> Applications, right click on Eclipse and select Move to Trash.
To uninstall JDK, open a Terminal and run the following command:
ls /Library/Java/JavaVirtualMachines
It will show the JDK you currently have. To remove it, run the following command
sudo rm -r /Library/Java/JavaVirtualMachines/<jdk-version>.jdk
where <jdk-version> is the name of the JDK.
If it is an Oracle JDK, it may also have some files in other folders. See this Stackoverflow question on how to get rid of those files.