2

Earlier my project used to be on Java 8 but now I am using Java 11 along with JavaFX 11 and now JavaFX has been decoupled from Java since Java 11. I haven't download the JavaFX SDK but added below dependency in pom.xml for getting required modules and jar files which were used to be part of Java itself in earlier versions.

       <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11</version>
        </dependency>

But I am getting compilation error can not be resolved to a type on @FXML annotation and FXMLLoader class.

Do I need to add some other/extra dependencies to resolve this issue?

José Pereda
  • 44,311
  • 7
  • 104
  • 132
Satish Pahuja
  • 209
  • 1
  • 6
  • 20

1 Answers1

16

FXML (@FXMLannotation, FXMLLoader...) were moved to the module javafx.fxml with the Java 9 release.

Before JavaFX 11, whenever you were calling something JavaFX related, you had all the javafx modules available within the SDK.

But now you have to include the ones you need:

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11</version>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>11</version>
</dependency>

Note that javafx.controls depends on javafx.graphics and java.base, so you don't need to include those. And javafx.fxml directly depends on javafx.base.

José Pereda
  • 44,311
  • 7
  • 104
  • 132