Error occurred during initialization of boot layer FindException: Module not found
Asked Answered
S

15

32

Executing a simple "Hello World" program using Java 9 results in the following error message:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module com.pantech.myModule not found

The command line that I executed was:

java --module-path bin -m com.pantech.myModule/com.pantech.myModule.HelloWorld

This command line is executed from the parent directory of my bin directory that contains all of the .class bytecode files.

The module-info.class file is located in the com.pantech.myModule directory that is located in the bin directory. The HelloWorld.class file contains the main method and is located in the package directory within the com.pantech.myModule directory. Therefore, the pathname of the HelloWorld.class file is bin\com.pantech.myModule\com\pantech\myModule\HelloWorld.class.

The HelloWorld class is in the com.pantech.myModule package (package name same as the module name).

I am using Windows 10 as the Operating System. From everything that I have read, the above command line should be correct. Any suggestions on how to fix this?

Saree answered 27/3, 2018 at 19:19 Comment(6)
In which directory is the compiled module file? Seems like the directory you need to add to module path is bin\com.pantech.myModuleBourges
The compiled module file (module-info.class) is located in the bin\com.pantech.myModule directory.Saree
Could you share the class definition(starting from package declaration) and module definition as well, for the above to be reproduced, please? And honestly, for such experiments, I take the quick-start here for reference. (you might want to cross verify the compilation commands as well)Punish
Module definition file (module-info.java) located incom.pantech.myModule directory contains the following: module myModule {} The source code for the HelloWorld file contains the following: package com.pantech.myModule; public class HelloWorld { public static void main(String [] args) { System.out.println("Hello World from module"); } }Saree
@D.Pante The answer by tretegfdg seems to be pointing out the mistake you made. That's why I suggest referring to the guide as well. The module name there is same as the package name com.greetings(in the sample), hence their command works. Also, refer to docs.oracle.com/javase/9/tools/java.htm for more details on the commands used.Punish
In Netbeans, I just used Clean and Rebuild Project and it worked.Karie
G
24

The reason behind this is that meanwhile creating your own class, you had also accepted to create a default class as prescribed by your IDE and after writing your code in your own class, you are getting such an error. In order to eliminate this, go to the PROJECT folder → src → Default package. Keep only one class (in which you had written code) and delete others.

After that, run your program and it will definitely run without any error.

Girth answered 13/7, 2018 at 12:40 Comment(0)
H
11

I had the same issue while executing my selenium tests and I removed the selenium dependencies from the ModulePath to ClassPath under Build path in eclipse and it worked!

Henceforward answered 15/1, 2020 at 5:44 Comment(2)
I faced the same issues and this fixed itArid
thanks Ankur, did the same and issue got fixed.Giblet
V
9

I had similar issue, the problem I faced was I added the selenium-server-standalone-3.141.59.jar under modulepath instead it should be under classpath

so select classpath via (project -> Properties -> Java Bbuild Path -> Libraries) add the downloaded latest jar

After adding it must be something like this

enter image description here

And appropriate driver for browser has to be downloaded for me i checked and downloaded the same version of chrom for chrome driver and added in the C:\Program Files\Java

And following is the code that worked fine for me

public class TestuiAautomation {

    public static void main(String[] args) {

        System.out.println("Jai Ganesha");
        try {
            System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Java\\chromedriver.exe");
            System.out.println(System.getProperty("webdriver.chrome.driver"));
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("no-sandbox");
            chromeOptions.addArguments("--test-type");
            chromeOptions.addArguments("disable-extensions");
            chromeOptions.addArguments("--start-maximized");
            WebDriver driver = new ChromeDriver(chromeOptions);
            driver.get("https://www.google.com");
            System.out.println("Google is selected");
        } catch (Exception e) {
            System.err.println(e);
        }

    }
}
Variant answered 30/12, 2020 at 2:24 Comment(0)
C
7

You say that your module-info.java contains

module myModule {}

That means it declares a module called myModule, not com.pantech.myModule. Pointing this from the command format:

 -m <module-name>/<main-class>
Casuist answered 29/3, 2018 at 0:11 Comment(2)
Thanks. The problem was solved by changing the module name in the module-info.java file to com.pantech.myModule instead of just myModule. The solution should have been obvious to me, but I guess that I was looking for something more obscure.Saree
Can you please explain? I am still not able to figure out what changes i am supposed to make.Mimetic
R
5

I had the same issue and I fixed it this way:

  1. Deleted all projects from eclipse, not from the computer.
  2. Created a new project and as soon as you write the name of your project, you get another window, in which is written: "Create module-info.java". I just clicked "don't create".
  3. Created a package. Let us call the package mywork.
  4. Created a Java class inside the package myWork. Let us call the class HelloWorld.
  5. I run the file normally and it was working fine.

Note: First, make sure that Java is running properly using the CMD command in that way you will understand the problem is on eclipse and not on JDK.

Reprehension answered 18/6, 2019 at 11:12 Comment(0)
T
2

I solved this issue by going into Properties -> Java Build Path and reordering my source folder so it was above the JRE System Library.

Tramel answered 6/3, 2020 at 5:38 Comment(1)
Tries Same thing but it does not resolve the errorMimetic
S
0

I just encountered the same issue after adding the bin folder to .gitignore, not sure if that caused the issue.

I solved it by going to Project/Properties/Build Path and I removed the scr folder and added it again.

Sputum answered 10/10, 2020 at 15:2 Comment(0)
R
0

check your project build in jdk 9 or not above that eclipse is having some issues with the modules. Change it to jdk 9 then it will run fine

Ronnie answered 14/10, 2020 at 15:47 Comment(0)
P
0

This problem occurred for me after deleting my bin folder in order to get it out of my git history. To fix it In Eclipse:

  1. Delete the project (from Eclipse, not from disk)
  2. Reimport it.
Prissie answered 15/3, 2021 at 21:20 Comment(0)
F
0

Try removing the JRE System Library from the Java build path of the project. Then add that again under the Modules by clicking Add Library.

Floss answered 22/6, 2021 at 15:14 Comment(0)
L
0

I struggled with this too in Eclipse and everything was working fine on the command-line but I kept getting a "module not found" when run in Eclipse. When I found the "Use 'release' option" under Java Compiler and ensured it is ticked then the app runs fine in Eclipse. That's using J17 and Eclipse 2022.

enter image description here

Lebel answered 9/8, 2022 at 10:15 Comment(0)
V
0

I have had a similar situation when I have imported an existing project. So, go to Run configurations, and create a new run configuration instead of replacing or reusing an exisitng one. the old running configuration may create the problem.

Venusian answered 17/2, 2023 at 16:44 Comment(0)
K
0

I solved this problem in this way

pre-requisite: latest "java jdk" must be installed in your system

Step - 1: Right click on your project -> select Build Path -> select configure Build Path

Step - 2: Select Libraries Tab

Step - 3: In classpath, select JRE System Library and click on Remove button (If your classpath is empty then you don't need to perform this step)

Step - 4: Now select ModulePath, click on Add Library Button

Step - 5: Select JRE System Library

Step - 6: Select Alternate JRE and click on Finish

Kana answered 26/4, 2024 at 10:21 Comment(0)
P
-1

I had a similar problem when for the default package. Just add a package and move your main class to it, and maybe this will resolve your problems.

Public answered 7/7, 2022 at 10:43 Comment(0)
U
-3

I faced same problem when I updated the Java version to 12.x. I was executing my project through Eclipse IDE. I am not sure whether this error is caused by compatibility issues.

However, I removed 12.x from my system and installed 8.x and my project started working fine.

Unfix answered 17/9, 2019 at 1:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.