Modules   «Prev  Next»

Module Info Exports Qualified

module org.module.util {
    requires transitive org.module.global;
    exports org.pkg.util to org.module.base;
}

We have changed the exports directive to a qualified directive. We have specified org.module.base as a friend. Changed the exports directive to a qualified directive using the "to" statement.
The package will only be read by the friends that we specify. Go back to our BaseEntity and run the class.
Create a 4th module
org.module.concrete

Remember as always, to do the following
  1. Below the newly created module.
  2. Right mouse click on src
  3. module-info.java

Right click on the src file and create a new Java Class.
The name of the new class for the package concrete is Couple.java.
Can be exported to multiple friend modules.
exports org.pkg.util to org.module.base, org.module.concrete;

Correct Syntax:
1 export directive and a comma delimited list for friends

Qualified Exports

When you are using exports to export a package in the module declaration, this package is visible to all modules that use requires to require it. Sometimes you may want to limit the visibility of certain packages to some modules only. Consider this example: a package was initially designed to be public to other modules, but this package was deprecated in later versions. Legacy code that uses the old version of this package should continue to work after migrating to Java 9, while new code should use the new versions. The package should only be visible to modules of the legacy code that still use the old version. This is done by using the to clause in exports to specify the names of modules that should have access. Listing 1-7 shows the module declaration of the JDK module java.rmi. You can see that package com.sun.rmi.rmid is only visible to module java.base and package sun.rmi.server is only visible to modules jdk.management.agent, jdk.jconsole, and java.management.rmi.

Listing 1-7. Module Declaration of JDK Module java.rmi
module java.rmi {
requires java.logging;
exports java.rmi.activation;
exports com.sun.rmi.rmid to java.base;
exports sun.rmi.server to jdk.management.agent,
jdk.jconsole, java.management.rmi;
exports javax.rmi.ssl;
exports java.rmi.dgc;
exports sun.rmi.transport to jdk.management.agent,
jdk.jconsole, java.management.rmi;
exports java.rmi.server;
exports sun.rmi.registry to jdk.management.agent;
exports java.rmi.registry;
exports java.rmi;
uses java.rmi.server.RMIClassLoaderSpi;
}


Summary:

in the last three lessons I have demonstrated how to create and declare modules using IntelliJ features as well as editing the module info dot Java files manually and we have used a combination of some of the directives available The next lesson will discuss will discuss unusual features about modules.