For example I have somefile-0.1.jar
jar file which contains JPMS module. Besides, I have a reference Module somemodule
to this module.
How to get jar file name by Module (using somemodule
reference)? I've examined Module API but didn't find a way to do it.
There's no guarantee that module was loaded from a modular JAR. In any case, I think this is close to what you are looking for:
Module m = ...
ModuleLayer layer = m.getLayer();
if (layer != null) {
ModuleReference mref = layer.configuration()
.findModule(m.getName())
.map(ResolvedModule::reference)
.orElseThrow(() -> new RuntimeException("should not happen"));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.