rashmi mardur
rashmi mardur

Reputation: 85

Why Java fail to run class- error occurred during initialization of boot layer- Module mods not found

I have gone through the java 9 jigsaw tutorial. I have been struggling to run class, java throws below error-

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 command-

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)

Am I missing anything?

Upvotes: 5

Views: 18263

Answers (4)

user3345469
user3345469

Reputation: 3

Thanks for the info

2 things I was doing incorrectly

1) Using the package path again like below

module\package\package.class

We should not retype the package path while executing the class.

2) Using the dos styled backslash instead of forward slash. We should always use the forward slash (/) to separate module with the class even you are executing in windows environment.

module/package.class

Upvotes: 0

Naman
Naman

Reputation: 31958

When you first compiled your code using javac command as-

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

What you ensured using -d directory was that to

Set the destination directory for class files.

in your case the mods folder where

If a class is part of a package, then javac puts the class file in a subdirectory that reflects the package name and creates directories as needed.

Hence you can take a look at the mods directory after executing the command, the .class for all(*.java) would exist in the corresponding directory structure as of their package name.


Then java tool option --module-path module path or -p module path specified in your next command :

Searches for directories from a semicolon-separated (;) list of directories. Each directory is a directory of modules.

Your listed directory according to which is mods, assuming which you must have created following the getting started link.


Followed by --module modulename[/mainclass] or -m module[/mainclass] in your command

Specifies the initial module to resolve and the name of the main class to execute if not specified by the module.

which in your case is the module name com.test and the main class com.test.HelloWorld.


Hence the complete correct syntax of the command shall be:-

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

Upvotes: 2

Rahul Sharma
Rahul Sharma

Reputation: 5834

Remove additional mods from module name-

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

Upvotes: 8

M A
M A

Reputation: 72864

The -m flag accepts the module name and the main class you want to run. The module name is com.test, hence the command to run the class should be:

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

The --module-path mods tells java where to search for to find com.test.

Upvotes: 3

Related Questions