Java module path argument confusion

Viewed 1191

This question is about the exact syntax of the JDK 14 "java" command.

The Oracle documentation states:

--module-path modulepath... or -p modulepath
    A semicolon (;) separated list of directories in which each directory is a directory of modules. 

while java --help on Ubuntu says:

-p <module path>
--module-path <module path>...
    A : separated list of directories, each directory
    is a directory of modules.

I tried it out using jar files and the separation by colon worked, it didn't work using semicolon. I used jar files, not directories. Is a jar file considered to be a "directory of modules"? Or is it just some undocumented feature that it is possible to use jar files instead of directories? Is there a relation to File.pathSeparatorChar?

1 Answers

As you've observed --module-path may contain references to directory or jars, I've checked on one of my module jars and it runs fine with this format:

java --module-path ..\jars\somemodule.jar;other.jar --class-path ..\jars\non-module.jar main.ClassName

It runs fine as this too:

java  --class-path ..\jars\somemodule.jar;other.jar;..\jars\non-module.jar main.ClassName

But not with the non-module here:

java  --module-path ..\jars\somemodule.jar;other.jar;..\jars\non-module.jar main.ClassName

And yes as commented above File.pathSeparatorChar is the splitter for PATH on the operating system and used as separator for items in classpath and modulepath. Windows ';' but normally ':' elsewhere.

Related