Using JavaFX with JDK 11 in Eclipse 2018-12
(For Introduction to Programming Using Java, Version 8.0)
With the release of Java 11, JavaFX was removed from Java and from the Java Development Kit. As of the December 2018 release of the Eclipse IDE, Eclipse fully supports Java&nbs;11. The question is, how to easily use JavaFX in that environment (for students using this textbook, in particular). The goal to make JavaFX automatically available in all projects in a given workspace. This can be accomplished by setting up the Preferences for the workspace, as shown in the image at the bottom of this page. The following downloads were used:
- For the JDK, I downloaded OpenJDK 11 from https://jdk.java.net/11/. (The version from Oracle should work the same.) The JDK is on my computer in the directory /home/eck/jdk-11.0.1.
- For JavaFX, I downloaded the JavaFX SDK 11 from https://gluonhq.com/products/javafx/. Several downloads are available; you want the "SDK" for your platform (not the "jmods"). The JavaFX SDK is on my computer in the directory /home/eck/javafx-skd-11. That directory contains a "lib" directory that includes several .jar files, such as javafx.bas.jar; a zip file, src.zip, with the JavaFX source code; and the binary support libraries needed by your platform.
After starting up Eclipse 2018-12, and opening the workspace that I intended to use for JavaFX development, I configured the workspace as follows, and as shown in the image below:
- In the Eclipse "Preferences", go to the "Java" section, then to "installed JRE's.
- If JDK 11 is already installed as a JRE, click "Edit". Otherwise, click "Add", and in the pop-up dialog box, set the "JRE home" to the directory that contains the downloaded JDK 11. (Click the "Directory..." button to select the directory with a GUI file browser.)
- Click the "Add External Jars" button in the dialog box. In the pop-up dialog that opens, browse to the "lib" directory inside the JavaFX SDK download, select all the .jar files in that directory, and click "OK". The .jar files will be added to the list of "JRE system libraries." This step is enough for JavaFX programs to be successfully compiled.
- In the "Default VM arguments" box, enter the following text, but changing
"/home/eck/javafx-sdk-11" to the
correct full path to the JavaFX directory on your computer (matching the path shown for the .jar
files in the "JRE system libraries" list):
--module-path=/home/eck/javafx-sdk-11/lib --add-modules=ALL-MODULE-PATH
These are options that should be added to the java command to run JavaFX programs. By entering them here, you will not need to enter them separately in every program's run configuration. (The value ALL-MODULE-PATH lets you use features from all JavaFX modules.) - Select all the JavaFX .jar files in the "JRE system libraries" list, and click the "Source attachment" button. In the pop-up that appears, select "External location", and set the "Path" to refer to the file src.zip from the lib directory of the JavaFX SDK download. (Click the "External File..." button to select the directory using a GUI file browser.) Click "OK". This will allow Eclipse to show you the Javadoc documentation for JavaFX classes and methods.
- Close the Add or Edit dialog box by clicking "Finish", and close the Preferences dialog box by clicking "Apply and Close".
