How to load resources from base module

Alan Bateman Alan.Bateman at
Wed May 17 10:23:17 UTC 2017

On 17/05/2017 10:54, wzberger wrote:

> Looks like I'm having an encapsulation issue with resources. Class B 
> belongs to module b and extends Class A in module a. Class B provides 
> resources which should be loaded from base class A.
> However, calling
>   getInstance().getClass().getResource(...)
> from a static method in class A fails while calling from class B works 
> fine. Because getInstance() returns Class B I wonder why the resource 
> can't be loaded. Any recommendation on how to get this working?
The details are in the javadoc but in summary:

Code in `b` can locate any resource in `b`.

Code in `a` can any locate any ".class" resource in `b`. It can also 
locate any resources in "non-package" locations such as META-INF/**. 
Resources that are located in b's packages are encapsulated and so `b`  
needs to `opens <package> to a` to allow code in module `a` to locate 
the resources.


More information about the jigsaw-dev mailing list