Java 启动层初始化时出错 FindException: Module not found
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49520858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error occurred during initialization of boot layer FindException: Module not found
提问by D. Pante
Executing a simple "Hello World" program using Java 9 results in the following error message:
使用 Java 9 执行一个简单的“Hello World”程序会导致以下错误消息:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module com.pantech.myModule not found
启动层初始化时出错
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 bindirectory that contains all of the .classbytecode files.
这个命令行是从bin包含所有.class字节码文件的我的目录的父目录执行的。
The module-info.classfile is located in the com.pantech.myModuledirectory that is located in the bindirectory. The HelloWorld.classfile contains the main method and is located in the package directory within the com.pantech.myModuledirectory. Therefore, the pathname of the HelloWorld.classfile is bin\com.pantech.myModule\com\pantech\myModule\HelloWorld.class.
该module-info.class文件位于com.pantech.myModule目录中的bin目录中。该HelloWorld.class文件包含 main 方法并位于目录内的包目录中com.pantech.myModule。因此,HelloWorld.class文件的路径名是bin\com.pantech.myModule\com\pantech\myModule\HelloWorld.class。
The HelloWorldclass is in the com.pantech.myModulepackage (package name same as the module name).
的HelloWorld类是在com.pantech.myModule包(package名称相同模块名称)。
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?
我使用 Windows 10 作为操作系统。从我读过的所有内容来看,上面的命令行应该是正确的。对于如何解决这个问题,有任何的建议吗?
回答by tretegfdg
You say that your module-info.javacontains
你说你的module-info.java包含
module myModule {}
That means it declares a module called myModule, notcom.pantech.myModule. Pointing this from the command format:
这意味着它声明了一个名为 的模块myModule,而不是com.pantech.myModule. 从命令格式指出这一点:
-m <module-name>/<main-class>
回答by Rahat Rajdev
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.
这背后的原因是,在创建自己的类的同时,您还接受了按照 IDE 的规定创建默认类,并且在您自己的类中编写代码后,您收到了这样的错误。为了消除这种情况,请转到 PROJECT 文件夹 → src→ 默认包。只保留一个类(您在其中编写了代码)并删除其他类。
After that, run your program and it will definitely run without any error.
之后,运行您的程序,它肯定会运行而不会出现任何错误。
回答by Abbe
I had the same issue and I fixed it this way:
我有同样的问题,我是这样解决的:
- Deleted all projects from eclipse, not from the computer.
- 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".
- Created a package. Let us call the package
mywork. - Created a Java class inside the package
myWork. Let us call the classHelloWorld. - I run the file normally and it was working fine.
- 从 eclipse 中删除了所有项目,而不是从计算机中删除。
- 创建了一个新项目,只要你写下你的项目名称,你就会得到另一个窗口,其中写着:“Create module-info.java”。我只是点击了“不创建”。
- 创建了一个包。让我们调用包
mywork。 - 在包内创建了一个 Java 类
myWork。让我们调用类HelloWorld。 - 我正常运行文件,它工作正常。
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.
注意:首先,使用 CMD 命令确保 Java 运行正常,这样您就会明白问题出在 Eclipse 而不是 JDK 上。
回答by manju450
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.
当我将 Java 版本更新到 12.x 时,我遇到了同样的问题。我正在通过 Eclipse IDE 执行我的项目。我不确定此错误是否由兼容性问题引起。
However, I removed 12.x from my system and installed 8.x and my project started working fine.
但是,我从系统中删除了 12.x 并安装了 8.x,我的项目开始正常运行。
回答by Ankur
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!
我在执行我的 selenium 测试时遇到了同样的问题,我在 eclipse 的 Build 路径下从 ModulePath 到 ClassPath 中删除了 selenium 依赖项,它起作用了!
回答by Kyler Conena
I solved this issue by going into Properties -> Java Build Path and reordering my source folder so it was above the JRE System Library.
我通过进入 Properties -> Java Build Path 并重新排序我的源文件夹解决了这个问题,使其位于 JRE 系统库之上。

