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

怎甘沉沦 提交于 2019-11-27 06:11:52

问题


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?


回答1:


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 error. In order to eliminate so go to PROJECT folder -> src folder -> Default package keep only one class(in which you had written code) and delete another one.

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




回答2:


You say 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>



回答3:


I had the same problem and I fixed this way:

  1. I deleted all projects from eclipse, not from the computer.
  2. I 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. I created a package. Let us call the package "mywork"
  4. I 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 working using CMD command in that way you will understand the problem is on eclipse not on JDK.




回答4:


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.



来源:https://stackoverflow.com/questions/49520858/error-occurred-during-initialization-of-boot-layer-findexception-module-not-fou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!