Why Java does not trigger a class error while initializing the boot layer. No Modules Found

I looked at the java 9 jigsaw tutorial . I try to run a class, java throws below errors -

java --module-path mods -m mods/com.test/com.test.HelloWorld
Error occurred during initialization of boot layer
java.lang.module.FindException: Module mods not found

Javac Team -

javac -d mods --module-source-path src $(find src -name '*.java')

I am using mac, java version -

$ java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

Did I miss something?

+4
source share
3 answers

Remove additional mods from the module name -

java --module-path mods -m com.test/com.test.HelloWorld
+5
source

The flag -maccepts the name of the module and the main class that you want to run. The name of the module com.test, so the command to start the class should be:

java --module-path mods -m com.test/com.test.HelloWorld

--module-path modstells javawhere to look com.test.

+3
source

javac -

javac -d mods --module-source-path src $(find src -name '*.java')

, -d directory, ,

.

mods,

, javac , .

, , .class (*.java) .


java --module-path module path -p module path, :

(;) . .

, mods, , .


--module modulename[/mainclass] -m module[/mainclass]

, , .

com.test com.test.HelloWorld.


Therefore, the complete correct command syntax should be: -

java --module-path mods    -m     com.test/com.test.HelloWorld
                   ^               ^         ^
           module directory  module name   main class
+3
source

Source: https://habr.com/ru/post/1687494/


All Articles