Issue
Hello I have a problem with my modular Java FX Application.
First of all I created a JavaFX Project with the Intellij Wizard. I added the Java FX lib:enter image description here
I also added the VM options:enter image description here
But I always get this errormessage:enter image description here
"Error occurred during initialization of boot layer java.lang.module.FindException: Module com.example.hudrava_test not found " Thank you.
Solution
Steps to address your issue
- Ensure that you are using the most recent stable version of Idea (currently 2021.3.2), Java and JavaFX (currently 17.0.2).
- Discard your current project.
- Create a new project.
- Follow the instructions at Create a new JavaFX project provided by Idea on how to use their wizard.
- If you follow the instructions exactly it should work.
- You don't need to add "the Java FX lib" to the project manually.
- The wizard will create a dependency in Maven or Gradle which includes the most common JavaFX modules.
- You don't need to download or use the JavaFX SDK mentioned at openjfx.io.
- You don't need to explicitly set any VM arguments such as
--add-modules
the wizard will create the amodule-info.java
file which references the modules.
Before proceeding any further, make sure that the basic generated project build and runs in your environment (according to the build and execution instructions documented by IntelliJ for the new JavaFX project wizard).
Using additional JavaFX modules
If you want to use additional JavaFX modules (e.g. javafx.media or javafx.web):
- Add the additional modules manually to the maven or gradle build file.
- Reimport the build file into the Idea project.
- Add requires clauses form the modules to the module-info.java.
Making your application non-modular
Even if your application is made non-modular, you still need to have JavaFX modules on the module path as that is the only way the execution of JavaFX is supported.
If you don't want a modular application, you can delete the module-info.java file and manually add VM arguments for the module path to the JavaFX and an --add-modules
switch.
I do not advise doing this step unless:
- You have a good reason not to have a non-modular application (e.g. rely on 3rd party dependencies which do not integrate easily with the Java module system), AND
- You have knowledge about how to make non-modular JavaFX applications.
Cause of the module find exception
The reason for your specific error:
java.lang.module.FindException: Module com.example.hudrava_test not found
is because you don't have module-info.java
for a module with that name on the module path. Note that is not a JavaFX module name, but something you have specified. You have tried to run the application by specifying a class name within the non-existent module, e.g.
java --module-path <somepath> -m com.example.hudrava_test/com.example.hudrava_test.HelloApplication
You can find out further info about that in:
However, you should not need to manually take the steps outlined in that answer, because, when you create a new project using the new JavaFX wizard, it will automatically create a module-info.java file and place your application's build output on the modulepath.
So the error was caused by something you did after creating the project with the wizard (I don't know what). When you create a new project, you should not have the error.
On module naming and underscores
The Jenkov module tutorial states:
A Java module name follows the same naming rules as Java packages. However, you should not use underscores (_) in module names (or package names, class names, method names, variable names etc.) from Java 9 and forward, because Java wants to use underscore as a reserved identifier in the future.
It is recommended to name a Java module the same as the name of the root Java package contained in the module - if that is possible (some modules might contain multiple root packages).
So, it is inadvisable to have underscores in either your module or your package name.
More info on module naming suggestions is provided in:
Answered By - jewelsea
Answer Checked By - Clifford M. (JavaFixing Volunteer)