15

With the recent Java 11 release, JavaFX is no longer included in the JDK. I have an existing JavaFX project. I am interested in learning how to change it from a Java 10 project to a Java 11. I am certain I have installed Java 11 correctly, and I am able to change the default SDK from Java 10 to Java 11. What I don't know is how I might get JavaFX working with Java 11.

I have downloaded the latest JavaFX release here. I have extracted it to my Java folder which contains my other JDK's, but I really don't know what to do at this point. I have read some lengthy guides that describe how to connect a project using Maven or Gradle, but I have never used these. Is there a way to add JavaFX support in the IntelliJ menus?

1
  • 2
    Have you seen this question? It already provides an answer for a regular JavaFX project (without Maven/Gradle, but also with Maven). If you want a short guide, check this blog post. Commented Oct 6, 2018 at 18:43

2 Answers 2

26

Download the appropriate JavaFX SDK for your operating system and unzip it to a desired location, for instance /Users/your-user/Downloads/javafx-sdk-11.

  1. Create a JavaFX project

enter image description here

Create a JavaFX project Provide a name to the project, like HelloFX, and a location. When the project opens, the JavaFX classes are not recognized. enter image description here

  1. Set JDK 11

Go to File -> Project Structure -> Project, and set the project SDK to 11. You can also set the language level to 11. Set JDK 11 enter image description here

  1. Create a library

Go to File -> Project Structure -> Libraries and add the JavaFX 11 SDK as a library to the project. Point to the lib folder of the JavaFX SDK. enter image description here

Once the library is applied, the JavaFX classes will be recognized by the IDE. enter image description here

Warning: If you run now the project it will compile but you will get this error:

Error: JavaFX runtime components are missing, and are required to run this application

This error is shown since the Java 11 launcher checks if the main class extends javafx.application.Application. If that is the case, it is required to have the javafx.graphics module on the module-path.

  1. Add VM options

To solve the issue, click on Run -> Edit Configurations... and add these VM options:

--module-path %PATH_TO_FX% --add-modules=javafx.controls,javafx.fxml

Note that the default project created by IntelliJ uses FXML, so javafx.fxml is required along with javafx.controls. If your project uses other modules, you will need to add them as well. enter image description here Click apply and close the dialog.

  1. Run the project

Click Run -> Run... to run the project, now it should work fine.

Detailed resource: https://www.jetbrains.com/help/idea/javafx.html

Sign up to request clarification or add additional context in comments.

3 Comments

At least you could add the link from where this is copied verbatim from.
Thanks Buddy! But you should follow the KISS rule to be a Good Developer :)
Is there a way to define global VM options for all configurations?
4

You could download a version of java which includes JavaFX from Azul. See: Download Azul Zulu Builds of OpenJDK. In that case there's no special setup involved to run JavaFx applications on Java 11 - it's built-in, just like in Java 8.

You can also download these 'full' versions from Bellsoft's JDK and JRE distribution site: Download Liberica JDK

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.