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
From IntelliJ it works like charm , i don't know what magic it runs behind .
What am i doing wrong ?
--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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With