IntelliJ doesn't load javafx packages from Maven dependencies (JavaFX 17)
Solution 1:
Update for JavaFX 17.0.0.1 release
The release of JavaFX 17.0.0.1 has resolved this issue and, when using JavaFX and Maven this is the version that should be used instead of 17 (which remains broken in Maven).
When defining a dependency on JavaFX 17 using Maven, ensure that the version defined for JavaFX dependencies is not 17 and is at least 17.0.0.1. Here is an example of a working dependency definition for JavaFX 17.0.0.1 Maven modules.
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.0.1</version>
</dependency>
Info on release versions and contents and the version number for the current latest release is available in the JavaFX release notes hosted at gluon.
For now, I will leave the rest of the original answer, which discusses some of the background information, as it was when it was originally created.
Maven modules for JavaFX versions prior to 17 (e.g. 16), still continue to function without issue. However, if you have the ability to upgrade and use JavaFX 17.0.0.1 or higher for your application, I encourage this.
JavaFX 17 will be maintained as a stable long-term release of JavaFX. It will maintain a stable feature set and receive bug and security fix support for many years.
Background
I was able to replicate this issue.
This is a known issue only affecting projects which rely on the initial JavaFX 17 release artifacts currently available in the Maven central repository.
See related question:
- JavaFX lib can not be build any more since JavaFX 17
Discussion of the issue on the openjfx-dev mailing list:
- https://mail.openjdk.java.net/pipermail/openjfx-dev/2021-September/031934.html
Workaround
One current workaround is, if your application relies on JavaFX artifacts from Maven central, to use JavaFX 16 rather than JavaFX 17 until this issue is fixed.
As this is quite a critical issue with the JavaFX 17 release, I would expect it will likely be addressed in an update to the JavaFX 17 release in the near future.
Environment
Mac OS (Catalina) 10.15.7
$ java -version
openjdk version "16.0.2" 2021-07-20
OpenJDK Runtime Environment Temurin-16.0.2+7 (build 16.0.2+7)
OpenJDK 64-Bit Server VM Temurin-16.0.2+7 (build 16.0.2+7, mixed mode, sharing)
IntelliJ IDEA 2021.2 (Ultimate Edition)
Build #IU-212.4746.92, built on July 27, 2021
Steps to replicate
- In Idea create a new JavaFX Project
- Select New | Project
- Choose JavaFX in the left tab.
- Choose Language: Java, Build System: Maven, Project SDK: 16
- Select Next -> Finish
- Test the new project.
- Right click on HelloApplication and select Run 'HelloApplication.main()'
- The application should run and display a JavaFX application window with a "Hello!" button.
- Change the JavaFX version
- Edit
pom.xml
- Change the JavaFX dependency versions from 16 to 17
- maven-compiler-plugin version can stay at 16.
- In the Maven tab, click the refresh icon to "Reload All Maven Projects"
- Test the updated project.
-
Right click on HelloApplication and select Run 'HelloApplication.main()'
-
Execution will now fail with the error message:
java: package javafx.fxml does not exist