As stated in the discussions you are discussing, the problem is the mapping between class loaders and modules.
When you load two modules M1 and M2 , both of which contain a non-exportable (aka hidden) package P through the CL class loader, JPMS should reject this configuration, because otherwise both key JPMS principles - strong encapsulation and reliable configuration - can be broken. Throwing an exception, here JPMS actually implements the requirement you specified and ensures that no conflicts can break anything later at runtime.
On the other hand, when you boot M1 and M2 through two boot loaders CL1 and CL2 , you actually create two runtime packages {CL1, P} and {CL2, P} , so there is no collision there, and Layer can be created.
The usability problem is that java uses a single bootloader for all application-level modules ("initial", created from command line arguments), which leads to a LayerInstantiationException . This is currently an open issue on the JPMS list, see here [here] ( http://openjdk.java.net/projects/jigsaw/spec/issues/#AvoidConcealedPackageConflicts ). But regardless of the resolution of the problem, if necessary, you should be able to deal with shared packages by writing a tiny main class that will create you Configuration (by the way, you will need an application container that supports JPMS).
source share