module resource loading - opens {package} when {package} only holds resources

Rob Bygrave robin.bygrave at gmail.com
Mon Sep 20 08:55:04 UTC 2021


Hi,
I have a case where I believe I have a module where I would like to use:

opens {package};

... *where {package} only contains resources*, there are no .class files in
{package}. Currently when {package} only contains resources, we get an
InvalidModuleDescriptorException error:

Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module:
/home/rob/github/avaje/test-modules/target/classes
Caused by: java.lang.module.InvalidModuleDescriptorException: Package
dbmigration not found in module

module test.modules {
  ...
  opens dbmigration;
}


*Background:*

I have a library that runs database sql scripts ("database migrations"). A
module will have a resources directory (typically called dbmigration) that
contains resources (sql scripts). The library loads the sql script
resources and executes them when required.


*Options that do work:*

A) Open the entire module
B) Add a dummy java class into the dbmigration package which then allows us
to specify *opens dbmigration; *in the module-info
C) Change the resource path from dbmigration to for example db-migration -
change the resource path to any non-valid package name, as Alexey Gavrilov
pointed out this is equivalent to opening it to all other modules.
D) Put extra code (that is otherwise unnecessary) into the same module as
the resources to load them and make them available to the library.


*Question*

Is there any chance that we can use opens for a resource path, when there
is no package per say?  Can we change to allows opens for resource only
paths? If we could, then this to me would seem like the nicest
option/approach for this case.


Thanks, Rob.


More information about the jigsaw-dev mailing list