I\'m having trouble getting IntellJ to recognize JavaFX packages. With a new JavaFX project, with OpenJDK 11, when trying to build the project, IntelliJ can\'t recognize the
As mentioned in the comments, the Starting Guide is the place to start with Java 11 and JavaFX 11.
The key to work as you did before Java 11 is to understand that:
JavaFX project
If you create a regular JavaFX default project in IntelliJ (without Maven or Gradle) I'd suggest you download the SDK from here. Note that there are jmods as well, but for a non modular project the SDK is preferred.
These are the easy steps to run the default project:
/Users//Downloads/javafx-sdk-11/lib/
. Once you do this you will notice that the JavaFX classes are now recognized in the editor.Before you run the default project, you just need to add these to the VM options:
--module-path /Users/
Run
Maven
If you use Maven to build your project, follow these steps:
Add the JavaFX 11 dependencies.
org.openjfx
javafx-controls
11
org.openjfx
javafx-fxml
11
Once you do this you will notice that the JavaFX classes are now recognized in the editor.
You will notice that Maven manages the required dependencies for you: it will add javafx.base and javafx.graphics for javafx.controls, but most important, it will add the required classifier based on your platform. In my case, Mac.
This is why your jars org.openjfx:javafx-controls:11
are empty, because there are three possible classifiers (windows, linux and mac platforms), that contain all the classes and the native implementation.
In case you still want to go to your .m2 repo and take the dependencies from there manually, make sure you pick the right one (for instance .m2/repository/org/openjfx/javafx-controls/11/javafx-controls-11-mac.jar
)
Replace default maven plugins with those from here.
Run mvn compile javafx:run
, and it should work.
Similar works as well for Gradle projects, as explained in detail here.
EDIT
The mentioned Getting Started guide contains updated documentation and sample projects for IntelliJ:
JavaFX 11 without Maven/Gradle, see non-modular sample or modular sample projects.
JavaFX 11 with Maven, see non-modular sample or modular sample projects.
JavaFX 11 with Gradle, see non-modular sample or modular sample projects.