Search code examples
javajava-9modularityjava-module

Java 9 Modularity with a packages


Let's say I have 2 modules:

  • module1 has the package package1

  • module2 has package2, package3 and package4

I want package1 to be visible to only package2 in module2. not to any other packages (package3 or package4) in module2.

Is this possible using module-info.java?


Solution

  • No, this is not possible. You can only export a package to the whole module:

    module module1 {
        exports package1 to module2;
    }