7

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

  1. File>New>Java Project com.hello project description

  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 project directory image

PS: after trying this solution my project structure looks like below

solution project structure

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

  • **com.hello** is not a valid project name for eclipse IDE –  Oct 14 '17 at 06:43
  • Could you share your project directory structure. Seems incorrect to specify the project name as `com.hello` as well. – Naman Oct 14 '17 at 06:43
  • @nullpointer. I have edited my question. added the directory structure image. – shekharyadav108 Oct 14 '17 at 06:47
  • @SamDev, already tried to change the name from com.hello to hello but the issue persists. – shekharyadav108 Oct 14 '17 at 06:50
  • 2
    @SamDev there's nothing wrong with `com.hello` as a project name. – Stephan Herrmann Oct 15 '17 at 11:19
  • Regarding the error during build: do you have the corresponding stacktrace? – Stephan Herrmann Oct 15 '17 at 11:22
  • I replayed all these steps with Oxygen.1a and all is fine for me. So, either you are not truly running Oxygen.1a (can happen e.g. if previously you installed the BETA Patch feature - please show us the exact version of plug-in org.eclipse.jdt.core), or there's a tiny difference in your project setup - in which case just zipping up the entire project would let others reproduce / investigate. – Stephan Herrmann Oct 15 '17 at 11:31
  • There's a thread in Eclipse forums, mentioning the same builder error. This post has been moved from the newcomers forum to JDT as https://www.eclipse.org/forums/index.php/t/1089434/ - so if you have more information on this, please add them to the forum thread, TIA. – Stephan Herrmann Oct 15 '17 at 12:04
  • I'm still facing this issue. Did you find a solution? – Arya May 14 '18 at 18:17

2 Answers2

2

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.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • I have followed your proposed solution. the issue still persists. – shekharyadav108 Oct 14 '17 at 07:17
  • I would like to give a little more context of the question. I was following [https://www.journaldev.com/13630/javase9-helloworld-module-ides-part4]. My _eclipse-oxygen_ didn't show the checkbox **Create module-info.java(9 or higher)** – shekharyadav108 Oct 14 '17 at 07:55
  • @shekharyadav108 Make sure you are using the Oxygen.1a release of Eclipse. Updated link in the answer. – Naman Oct 14 '17 at 08:00
  • Here are my eclipse details. Eclipse Java EE IDE for Web Developers. Version: Oxygen.1a Release (4.7.1a) Build id: 20170928-1841 – shekharyadav108 Oct 14 '17 at 08:10
  • I think [https://www.eclipse.org/forums/index.php?t=msg&th=1089414&goto=1774411&] is also a similar issue. – shekharyadav108 Oct 14 '17 at 08:12
  • @shekharyadav108 Also note that you have started building a Maven project which is not what the link shared by you suggests. So that is another thing to clear off. Would suggest starting afresh and trying it with minimal dependencies on other frameworks. Then gradually involve them...Anysuch dependencies are not visible in your setup that could cause this. I've tried explaining the error you get in [one of my answers previously](https://stackoverflow.com/questions/46132019/java-io-ioexception-invalid-constant-type-19-at-5/46133927#46133927)..Make sure you are not missing some info. – Naman Oct 14 '17 at 08:13
  • @shekharyadav108 "Build id: 20170928-1841" is **not** Oxygen.1a, the correct build ID is "20171005-1200", perhaps you should show us the full list of installed plug-ins (from About Eclipse > Installation Details > Plug-ins). – Stephan Herrmann Oct 15 '17 at 11:39
  • 1
    @shekharyadav108 the checkbox **Create module-info.java** has been removed (as of 2017-06-14) in favor of a new command **Configure > Create module-info.java** (right click on the project). Apparently, the tutorial you followed is outdated. – Stephan Herrmann Oct 15 '17 at 11:55
  • Awesome. The key here is the placement of "module-info.java" at the right place in the folder structure. Thanks for letting us know. – Amit Kumar Dec 21 '17 at 07:45
0

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

Govinda Sakhare
  • 5,009
  • 6
  • 33
  • 74
  • it is maven project. Check there is this Small `m` icon on an eclipse project name. – Govinda Sakhare Oct 14 '17 at 07:01
  • @nullpointer, previously I have created java project. later changed to maven project. trying back and forth to make it work. – shekharyadav108 Oct 14 '17 at 07:04
  • @shekharyadav108 Ya but in both case the solution should be moving the package to src folder as I already suggested [in the answer](https://stackoverflow.com/a/46741738/1746118), since Maven also follow the same structure. – Naman Oct 14 '17 at 07:06