JavaFX does not exist using Java 9 and Intellij Idea

Viewed 21125

I am using Intellij Idea to compile a project that uses Maven dependencies and Intellij keeps telling me that my project has 50 something errors because JavaFX does not exist.

Intellij is not highlighting all the javafx dependencies in my code as errors, it is just that once I press the run and compile the program says that everything in JavaFX does not exists.

I tried to redownload the latest JDK (Java 9.0.1) and that did not fix it. I went into the Default Project Structure and Project Structure to make sure it was using the correct jdk and that did not fix the issue. All the jdks I am using seem to list the javafx packages as included in the project.

This is also only an issue for a particular project that I am working on with a friend. We may have to move over all our code into a new project, however I am not sure if that will fix anything.

Any suggestions?

6 Answers

Try to set project language level to "9" in "Project Structure | Project"

I missed the modules in my gradle.build. Had to update

javafx {
  version = "11"
  modules = [ 'javafx.controls', 'javafx.fxml' ]
}

In Java9+ some modules are not included in JRE/JDK. The solution is to add thore libraries explicitly.

For maven pom file for Java9 I used

<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-fxml -->
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>11</version>
</dependency>

Than I can use desired libray for including of TextField.

import javafx.scene.control.TextField;
Related