Return to site

JPMS: 'exports' directive

· java

An exports module directive specifies one of the module’s packages whose public types (and their nested public and protected types) should be accessible to code in all other modules.

Here a module (com.mycompany.mypackage) that can be used by other modules because it exposes some package (com.mycompany.mypackage.api) to these foreign modules.


The syntax would be:

Now this module com.mycompany.mypackage has made the com.mycompany.mypackage.api package available at the foreign modules.

In all, both the dependent and the exporting modules must express what is provided and what is consumed.
So remember to export packages, but require modules.

Remember the golden rule: EXPORT A PACKAGE, BUT REQUIRE A MODULE.

A module can expose any number of packages to foreign modules, but they must each include their own export statement.

There's also no support for comma-delimited packages that can be specified in one export statement.
So this would give a compilation error.
There's also no support for wild cards.