[Question] Accessibility of each modules
Alan Bateman
Alan.Bateman at oracle.com
Tue Sep 5 13:16:56 UTC 2017
On 05/09/2017 14:08, KUBOTA Yuji wrote:
>
> My following example program shows that automatic module can't read
> exported package by explicit module.
>
> $ /jdk-9/bin/jar -d --file mlibs/org.astro.jar
> org.astro jar:file:///jigsaw-sample/mlibs/org.astro.jar/!module-info.class
> exports org.astro
> requires java.base mandated
>
> $ /jdk-9/bin/jar -d --file libs/com.greetings.jar
> No module descriptor found. Derived automatic module.
>
> com.greetings automatic
> requires java.base mandated
> contains com.greetings
>
> $ /jdk-9/bin/java -p mlibs:libs -m com.greetings/com.greetings.Main
> Exception in thread "main" java.lang.NoClassDefFoundError: org/astro/World
> at com.greetings/com.greetings.Main.main(Main.java:7)
> Caused by: java.lang.ClassNotFoundException: org.astro.World
> at
> java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
> at
> java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
> at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
> ... 1 more
>
The issue here is that org.astro is not resolved because no module
requires org.astro. If you add `--add-modules org.astro` to the command
line then it will ensure that this module is resolved and you should see
that com.greetings reads it.
-Alan
More information about the jigsaw-dev
mailing list