Modules A and B export package some.package to module C in Java 9

7.8k views Asked by At

I have three modules module-a, module-b and module-c. When I run my application I get the following:

Error occurred during initialization of boot layer java.lang.module.ResolutionException: Modules module-a and module-b export package some.package to module module-c

What does it mean, taking into consideration that module-c doesn't import some.package and how to fix it?

1

There are 1 answers

6
Nicolai Parlog On BEST ANSWER

Looks like you've created a split package, meaning two modules (module-a and module-b in your case) contain the same package (some.package). The module system does not allow that. If you place both modules on the module path, you will get this error regardless of whether the package is exported or whether a third module depends on the other two.

The fix is, not to create modules that share the same package. This is not only a technical solution, it also improves the design by making sure each module has a specific and unique API.