The Practice and Philosophy of Object-Oriented Programming in Java
How to Add JavaFX to an IntelliJ Project
This document assumes that you have already installed and set up Java and IntelliJ IDEA (if not, start here). If you are using Java 8, JavaFX is already bundled with your JDK so you do not need to take any further steps. With the advent of Java 11 in 2018, however, JavaFX was removed from the JDK so that it could evolve at its own pace as an independent open-source project guided by Oracle and others in the OpenJFX community.
Step 1: Download JavaFX
javafx-sdk(with version number appended). Unzip the folder and move it to a permanent location on your hard drive.
Step 2: Adding the JavaFX libraries to an IntelliJ project
If you create a new JavaFX application or open an existing one, you will notice compile-time
errors in the editor: names of classes in the JavaFX API are not recognized. To fix this, you
need to add the JavaFX libraries to the project. First, click on the
File menu and
Structure. In the dialog that appears, select the
Libraries tab and click the
+ icon to add a new Java library:
javafx-sdk folder and select the
Click the OK button to complete the process.
At this point, all compile-time errors have been resolved. If you try to run the application and a
ClassNotFound exception is thrown, a fourth and final step, described next, will be needed.
Step 3: Editing the Project's Run Configuration
Note: This step may not be necessary. Try to run a JavaFX application after completing the first three steps. If you succeed, there is no need to edit your project's run configuration.
run menu, select
configurations. In the
dialog that appears, you will see a field for VM options. You need to enter two options into
this field with the following general form:
--module-path %PATH_TO_FX% --add-modules=%FX_MODULES_NEEDED%
Instead of %PATH_TO_FX%, include the actual path to the JavaFX SDK
lib directory. The path syntax will depend on your operating system. For the
example illustrated in the preceding steps, the first VM option would be:
--module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib"
The quote marks are necessary since the name of one of the directories in the path contains a space.
The JavaFX SDK is partitioned into seven modules. Include a comma-separated list of the ones your project will need in place of %FX_MODULES_NEEDED%. For example:
Later you can add other modules if you need to, or remove some, by editing your run configuration again.
If the application does not run at this point, close and restart the IDE.
For troubleshooting information, consult the JetBrains help page.