Issue
I'm working on a JavaFX project, I started using Netbeans having no problems then switched to IntelliJ Idea where I'm having troubles. At first, some imports like java.sql and javafx were not working, so I added a module-info.java file to the src folder where I put all the required imports, like this:
module blood {
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
requires java.sql;
requires java.desktop;
requires jdk.jfr;
opens sample;
}
The module has the same name as the project "blood". Now i have no errors concerning the imports but when i run my project i'm getting this:
"C:\Program Files\Java\jdk-11.0.2\bin\java.exe" --module-path C:\Users\USER\Downloads\javafx-sdk-11.0.2\lib --add-modules=javafx.controls,javafx.graphics,javafx.fxml --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED -Djava.library.path=C:\Users\USER\Downloads\javafx-sdk-11.0.2 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.4\lib\idea_rt.jar=50526:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.4\bin" -Dfile.encoding=UTF-8 -m blood/sample.Main
Error occurred during initialization of boot layer
java.lang.module.FindException: Module blood not found
Process finished with exit code 1
I also added to the VM options this line:
--module-path "C:\Users\USER\Downloads\javafx-sdk-11.0.2\lib" --add-modules=javafx.controls,javafx.graphics,javafx.fxml
What should i do?
Solution
--module-path C:\Users\USER\Downloads\javafx-sdk-11.0.2\lib
is not sufficient to load the module blood
that you've created for your application. On the other hand, the command-line argument
-m blood/sample.Main
expects blood
module with sample.Main
class to run the application. That is the reason the error reads
java.lang.module.FindException: Module blood not found
So the solution to it would be adding the output folder where the module blood
is getting build.
--module-path C:\Users\USER\Downloads\javafx-sdk-11.0.2\lib;<project-output-diretory>
The openjfx-docs section "JavaFX and IntelliJ" further has a sub-topic "Modular from IDE" which talks about the "Add VM options" to be clear about this configuration.
Answered By - Naman
Answer Checked By - Mary Flores (JavaFixing Volunteer)