Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 757
GOXR3PLUS Avatar asked Jun 04 '19 08:06

GOXR3PLUS


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
like image 187
ZhekaKozlov Avatar answered Nov 09 '22 22:11

ZhekaKozlov


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).

like image 36
Raj Avatar answered Nov 10 '22 00:11

Raj


Looks like you are trying to run it from desktop and the file is not present at the desktop folder.

please refer the below link and use relative path to execute

Unable to resolve module using --module-source-path

like image 24
Kamu Avatar answered Nov 09 '22 22:11

Kamu