Module resource loading
Alan Bateman
Alan.Bateman at oracle.com
Wed Jun 9 15:08:30 UTC 2021
On 08/06/2021 20:20, Alexey Gavrilov wrote:
> Note that *Module 2* cannot contain its own resources under `dir1` and
> `dir2` directories because they are already encapsulated in *Module 1*. If
> you try adding `dir1` you will get the following error:
>
> Error occurred during initialization of boot layer
> java.lang.LayerInstantiationException: Package dir1 in both module
> module_one and module module_two
Resource encapsulation is complicated.
The basic guideline is that code should use Class::getResourceXXX or
Module::getResourceXXX to locate a resource in its own module.
ClassLoader::getResourceXXXX is for locating other resources in other
components on the class path or module path. Services are often a better
choice for cases where the resource is configuration that names a class.
Two modules with resources in the same "package" is the same as split
package issue. Are the two modules in question closely related, meaning
sharing a name space, or they are completely unrelated?
-Alan.
More information about the jigsaw-dev
mailing list