0

I can run a Java module from the command line without issues as follows:

java -p "dir/with/module1;dir/with/module2" -m my.module.name
//runs fine

However, when I reverse the arguments, putting -m (--module) before -p (--module-path), it doesn't work and results in the following error:

java -m my.module.name -p "dir/with/module1;dir/with/module2"
Error occurred during initialization of boot layer
java.lang.module.FindException: Module my.module.name not found

Is this expected behavior? Can someone confirm whether the order of the -p and -m arguments matters?

Here's my Java version for reference:

$ java --version
openjdk 11.0.12 2021-07-20 LTS
OpenJDK Runtime Environment Corretto-11.0.12.7.1 (build 11.0.12+7-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.12.7.1 (build 11.0.12+7-LTS, mixed mode)
JellyRaptor
  • 725
  • 1
  • 8
  • 20

1 Answers1

2

Official documentation:

To launch the main class in a module: java [options] -m module[/mainclass] [args...]

-p is an option that must come before -m

Geoff
  • 428
  • 2
  • 8
  • 2
    Or, in other words, everything after the `-m module[/mainclass]` argument is passed to the `main` method in the string array argument, without interpretation. – Holger Oct 08 '21 at 10:10