Module moduleA not found in module source path , trying to compile

Viewed 1193

After this question was answered i published java 9 modules tutorials + examples on Github and how to run for future users :

I have the below very simple structure:

src 
│   module-info.java
│ 
└───moduleA
    └───pack1
            Main.java

module-info.java :

module moduleA {

}

Main.java:

package moduleA.pack1;
public class Main{

 public static void main(String[] args){
   System.out.println("Hello Java 11");
 }
}

And i am trying to compile and then run this modular java application which is very simple .

So from the cmd i am running :

Compile

javac --module-source-path src -d out -m moduleA

Run

java  --module-path out -m moduleA/pack1.Main

enter image description here

From IntelliJ it works like charm , i don't know what magic it runs behind .

What am i doing wrong ?

3 Answers

--module-source-path is usually used to compile multiple modules at once. But of course, you can compile a single module with it if you want. However, you have to move the source files to the directory with the module name:

src
└───moduleA
    │───module-info.java
    └───moduleA
        └───pack1
            └───Main.java

Also, you should fix the command line which runs your module:

java --module-path out -m moduleA/moduleA.pack1.Main

The exact error i faced..(i was following the same example) Just make sure the type of file in windows against "module-info" is "JAVA File"

i did edit via notepad++ and selected java lang , changed the type explicitly to java.it worked for me,nothing extra i did as mentioned in some comments. i am pretty sure this must be the case for u also.

This error occurs if javac fails to locate module-info.java, so there should something wrong with that file(in my case it was file type)

PS: please give credits/author info (Durgasoft) since you have copied the notes information from there(in git hub).

Related