What is the correct way to get ModuleReference
only an object Module
in Java 9?
Consider these two methods of accessing java.base
:
Module mod = ModuleLayer.boot().findModule("java.base").orElse(null);
ModuleReference modRef = ModuleFinder.ofSystem().find("java.base").orElse(null);
mod
has a method Set<String> getPackages()
, but you only get package names, you cannot list resources in each package.
modRef
has a method ModuleReader open()
, but ModuleReader
has a method Stream<String> list()
that lists the resources in the module, what do I need to do.
However, for automatic (and therefore unnamed) modules created by adding non-modular jarfiles to the classpath, you cannot get ModuleReference
from ModuleFinder.ofSystem().find(String name)
or ModuleFinder.ofSystem().findAll()
- you can only get a Module
link from getClass().getModule()
.
I can not find a way to get ModuleReference
for automatic modules. I also cannot find a way to get ModuleReference
from the object Module
, which means that I cannot list the resources in Module
if the module is automatic and / or unnamed.
Surely there should be a way to get ModuleReference
for a given (already loaded) Module
?
source
share