'JavaFX Modular Application, java.lang.module.FindException: Module javafx.controls not found (Java 11, Intellij)
I have a problem with my modular JavaFX application. I created a JavaFX project and added the JavaFX lib and JavaFX modules get recognized. However, I keep getting these error message:
Error occurred during initialization of boot layer java.lang.module.FindException: Module javafx.controls not found
Image for the complete setup is attached hereby:
edit:
this is all the errors messages:
/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -Djava.library.path=
/home/thenekolite/Documents/JavaTools/javafx-sdk-11.0.1/lib --module-
-path=~/Documents/JavaTools/javafx-sdk-11.0.1/lib
--add-modules=javafx.controls,javafx.fxml
--add-modules javafx.base,javafx.graphics --add-reads
-javaagent:/home/thenekolite/idea-IU-183.4588.61/
lib/idea_rt.jar=35937:/home/thenekolite/idea-IU-183.4588.61/bin
-Dfile.encoding=UTF-8 -classpath /home/thenekolite/IdeaProjects/
Latihan1/out/production/Latihan1:/home thenekolite/Documents/JavaTools/
javafx-sdk-11.0.1/lib/src.zip:/home/thenekolite/Documents/JavaTools/
javafx-sdk-11.0.1/lib/javafx-swt.jar:/homehome/thenekolite/Documents
/JavaTools/javafx-sdk-11.0.1/lib/javafx.fxml.jar:/home/thenekolite/
Documents/JavaTools/javafx-sdk-11.0.1/libjavafx.media.jar:
/home/thenekolite/Documents/JavaTools/javafx-sdk-11.0.1/lib/
/javafx.swing.jar:/home/thenekolite/Documents/JavaTools/javafx
sdk-11.0.1/lib/javafx.controls.jar:/home/thenekolite/
Documents/JavaTools/javafx-sdk-11.0.1/lib/javafx.graphics.jar
-p /home/thenekolite/Documents/JavaTools/javafx-sdk-11.0.1/lib/
/javafx.base.jar:/home/thenekolite/Documents/
JavaTools/javafx-sdk-11.0.1/lib/javafx.graphics.jar sample.Main
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found
I also add the vm options:
but still, i got this error messages.
Solution 1:[1]
Since you're running as a Non-Modular application from IntelliJ, you would need to ensure adding the VM argument as :
--module-path /path/to/javafx-sdk-11.0.1/lib --add-modules=javafx.controls,javafx.fxml
You can follow the documentation link as JavaFX and IntelliJ and then Non-modular from IDE for complete setup details.
Solution 2:[2]
i had the same issue with netbeans, i added the VM options correctly, but i got this error, the solution for my case was to disable Compile on save from project properties -> Build -> Compiling
Hope this will help you in intellij or anyone having the same problem in netbeans.
Solution 3:[3]
In IntelliJ, when creating your project, when you do the New > Project wizard, select the "BootstrapFX" dependency.
This adds requires "org.kordamp.bootstrapfx.core;" to your modules-info.java and solved the problem for me in IntelliJ 2021.2.1.
Solution 4:[4]
Advice: Use the new project wizard instead of the JavaFX SDK
Don’t use a downloaded JavaFX SDK. Use a build tool, e.g., Maven, to add JavaFX and other dependencies. Use the Create new JavaFX project wizard to generate your project.
The wizard will configure a modular project based on a build tool (maven or gradle).
IMO this is a much easier and better way to create a new project. A project created this way is easier to use, more useful and future-proof as:
The IDE will be able to run the project without having to manually specify command line arguments for the module system. This is because:
- The IDE can automatically find the required modules from the maven dependencies, so you don't need to specify a
--module-path
manually. - The project contains a
module-info.java
file so you don't need to--add-modules
manually.
- The IDE can automatically find the required modules from the maven dependencies, so you don't need to specify a
The project is self-contained and easier to share:
- If somebody else wants to use it, they just need to have a standard Java+Maven or Gradle install rather than also finding and downloading a JavaFX SDK.
The project can be easily built using a continuous integration build tool like Jenkins:
- With a manual SDK dependency setting up Jenkins to build the project would be tricky.
The project can be linked to a runtime using jpackage or jlink.
- This is because it is a modular application.
You can use the dependency mechanism to add dependencies on other software libraries.
- Any non-trivial application will need additional dependencies; it is best to manage the JavaFX dependencies and other dependencies the same way IMO.
Troubleshooting steps for using the JavaFX SDK
You have an environmental issue so I can't give a definitive answer, just provide troubleshooting steps so you can repair your environment.
Follow the OpenJFX IO Getting Started steps for Intellij.
- If you follow the steps exactly, it should work.
If you want to continue using the sdk, put it in a location without spaces, or quote the path when using it.
The Idea UI for VM args is extremely confusing, ensure that you have actually set VM args and not program args. To do that, see this answer to:
Expand the Java execution command which Idea puts in the console pane on execution and copy it as text to add to your question formatted as code.
When you look at the Java execution command, ensure that the module arguments are before your main class name, not after.
Copy the execution command to a command line and try running it there.
When supplying the module path, try using the actual path (properly quoted if that is required), rather than an environment variable.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Naman |
Solution 2 | Diaf Badreddine |
Solution 3 | Eddie T |
Solution 4 | jewelsea |