java application not working with java9 and eclipse

我的梦境 提交于 2019-12-13 13:25:15

问题


I am trying to create a HelloWorld module of Java9 following steps were given below.

  1. File>New>Java Project

  2. Right-click project(i.e. com.hello)>New>Source Folder>enter source folder name(.e. com.hello)

  3. Right click Source Folder(i.e. com.hello)>New>Package>enter name(same as source folder name i.e com.hello)
  4. 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;
    }
    
  5. 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


回答1:


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.




回答2:


Please check the @nullpointer answer. I'd like to add few more things. What I can see is, you have created maven project. And you have entered package name in the artifact id column.

Please change the group id and project name as per your need,

group name : com.hello
artifact-id: your_project_name

Please go through this link once Create a maven project in eclipse



来源:https://stackoverflow.com/questions/46741683/java-application-not-working-with-java9-and-eclipse

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