Java应用程序无法与Java9和Eclipse一起使用 [英] java application not working with java9 and eclipse
问题描述
我正在尝试按照以下步骤创建Java9的HelloWorld模块.
-
文件>新建> Java项目
-
右键单击项目(例如com.hello)>新建>源文件夹>输入源文件夹名称(例如 com.hello )
- 右键单击源文件夹(即com.hello)>新建>包>输入名称(与源文件夹名称即com.hello相同)
-
右键单击源文件夹(即com.hello)>新建>文件>输入文件名((模块的java9标准文件名,即module-info.java)
module com.hello { exports com.hello; }
-
右键单击 Package(即com.hello)> New>输入类名(即HelloWorld)
package com.hello; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }
右键单击 HelloWorld>运行方式> Java应用程序,它会抛出
启动层初始化期间发生错误
java.lang.module.FindException:找不到模块com.hello
我的项目目录结构
PS:尝试使用此解决方案我的项目结构如下所示
注意:我注意到了另外一件事.之后保存更改.食(氧气)
在构建过程中发生错误. 在项目"com.hello"上运行构建器"Java Builder"时出错. 未知常量池类型19
假设您正在使用 在Eclipse中进行Maven:逐步安装.
I am trying to create a HelloWorld module of Java9 following steps were given below.
File>New>Java Project
Right-click project(i.e. com.hello)>New>Source Folder>enter source folder name(.e. com.hello)
- Right click Source Folder(i.e. com.hello)>New>Package>enter name(same as source folder name i.e com.hello)
Right click Source Folder(i.e. com.hello)>New>File>enter file name(java9 standard file name for module which is module-info.java)
module com.hello { exports com.hello; }
Right Click Package(i.e com.hello)>New>enter class name(i.e. HelloWorld)
package com.hello; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }
Right click on HelloWorld>Run As>Java Application It throws
Error occurred during initialization of boot layer
java.lang.module.FindException: Module com.hello not found
My project directory structure
PS: after trying this solution my project structure looks like below
Notice: I have noticed one more thing. Afte saving the changes. eclipse(oxygen) throws
Errors occurred during the build. Errors running builder 'Java Builder' on project 'com.hello'. Unknown constant pool type 19
Assuming, that you are using Eclipse Oxygen.1a (4.7.1a) Release released on October 11, 2017 to support JPMS and Junit5 you can adapt to the following -
While you are creating a new Java project, you need to make sure your com.hello
package and module-info.java
is under the src
folder of the project. You can move them in your project to follow the complete tree that shall look like:-
com.hello[project]
|
|-src
| |
| |-- com.hello[package]
| | |
| | |- HelloWorld.java [your class]
| |
| |--module-info.java
Note:- In case you are attempting to create a project based on Maven(pom.xml
visible in your structure), you might want to follow answers to Maven in Eclipse: step by step installation.
这篇关于Java应用程序无法与Java9和Eclipse一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!