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"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With