Przemek Baj
Przemek Baj

Reputation: 494

java.lang.module.FindException: Module not found

I must say that I am not much familiar with Java, I am working on assignment for my university classes.

I want to make a Desktop Application with JavaFX and SceneBuilder, I'm using this tutorial on YouTube: https://www.youtube.com/watch?v=DH3dWzmkT5Y

Everything is working fine until in 17:25 he created module-info.java file

module HotelBookingSystemTest1 {
    requires javafx.graphics;
    requires javafx.fxml;
    requires javafx.controls;
    requires java.sql;
    requires mysql.connector.java;

    opens sample;
}

I do the same in my project, but after running I am getting this error:

/home/prem/.jdks/openjdk-15.0.2/bin/java --module-path /home/prem/Downloads/javafx-sdk-16/lib --add-modules javafx.controls,javafx.fxml -Djava.library.path=/home/prem/Downloads/javafx-sdk-16/lib -javaagent:/snap/intellij-idea-community/289/lib/idea_rt.jar=44433:/snap/intellij-idea-community/289/bin -Dfile.encoding=UTF-8 -m HotelBookingSystemTest1/sample.Main
Error occurred during initialization of boot layer
java.lang.module.FindException: Module HotelBookingSystemTest1 not found

Process finished with exit code 1

I'm pretty sure that I put the file in the right place, here is my project directories tree:

enter image description here

Could someone help me with fixing that error and explain why this is happening? Thank you!

Upvotes: 7

Views: 61336

Answers (4)

Ajay Chaudhari
Ajay Chaudhari

Reputation: 1

To configure the build path in your project within Eclipse IDE, follow these steps:

  1. Right-click on your project within the Project Explorer or Navigator view.
  2. From the context menu, select "Build Path" and then "Configure Build Path".
  3. In the "Build Path" dialog that opens, navigate to the "Libraries" tab.
  4. Select "JRE System Library" from the list and click on the "Remove" button to remove it from the build path.
  5. Next, click on the "Modulepath" tab.
  6. Click the "Add Library..." button.
  7. In the "Add Library" dialog, select "JRE System Library" and click "Next".
  8. Choose the appropriate "Execution Environment" and click "Finish".
  9. Finally, click "Apply and Close" to save your changes.

By following these steps, you can effectively manage the build path configuration for your project

Upvotes: 0

Ted N
Ted N

Reputation: 1

For anyone getting this error using maven just move the module-info file into your source directory which normally for maven projects is "src/main/java" or if its different move youre module-info file from project directory to the new source directory it should work

Upvotes: 0

Daniel Branco
Daniel Branco

Reputation: 71

To complement the previous answer, you can follow the path you found on "File -> Project Structure -> Project -> Project compiler output" in the project structure frame and there you can copy the module path with Right Click on the module name -> Copy Path.

Then you can find the VM Options clicking on Run -> Edit Configurations.

Upvotes: 1

ETHN
ETHN

Reputation: 74

You're getting that error because you didn't include its path in your VM options. All you have to do is find out where your code is outputting to and add that path to any existing ones such as this one:

--module-path "<your-path>" --add-modules javafx.controls,javafx.fxml

It looks like your project's output directory is "out" (more than likely under productions) but you can always double check this by going to File -> Project Structure -> Project -> Project compiler output and then figure out where your module is located from there (in your case you'd be looking for HotelBookingSystemTest1). After copying its address and adding it to the code above it should look something like this:

--module-path "<your-path>;<copied-address>" --add-modules javafx.controls,javafx.fxml

Here is one of my paths for reference, although in this case my output directory was "classes":

--module-path "C:\Program Files (x86)\JavaFX\javafx-sdk-16\lib;C:\Users\ethan\Documents\Code\GeneralPlanner\classes\production" --add-modules javafx.controls,javafx.fxml

Also make sure the SDKs in your run configuration and module settings are the same. If it gives you an error about the sql connector or any other module not found, be sure to add their paths to the existing ones as well (same way with the semicolon).

Upvotes: 4

Related Questions