Given two modules m1
and m2
on the module path:
java -version
openjdk version "11.0.2" 2019-01-15
java -p M2/bin:M1/bin --list-modules
...
m1 <path>M1/bin/
m2 <path>M2/bin/
When running module m2
, and specifying --add-reads
from m2
to m1
:
java -p M2/bin:M1/bin --add-reads m2=m1 -m m2/p2.C2
WARNING: Unknown module: m1 specified to --add-reads
...
Java cannot see the module m1
, even though when using --list-modules
it is clearly visible.
How to make --add-reads
recognize the module?
Unlike requires
in module-info.java
, --add-reads
will not add the module to the module graph, even though the documentation for --add-reads
says: This is, essentially, a command-line form of a requires clause in a module declaration
. Turns out that the actual equivalent is --add-modules
combined with --add-reads
:
java -p M2/bin:M1/bin --add-modules m1 --add-reads m2=m1 -m m2/p2.C2