Importance of Module Descriptor in a Module in Java 9?

A module is a collection of code in the form of classes organized in packages and static resources such as property files or others. It provides the outside environment with all the information that can be required to use that module. The module descriptor is a key source of the module system, and it's compiled version of a module declaration specified in a file named "" file at the root of the module’s directory hierarchy.

The module describes itself by a module declaration as below

module com.myproject.module1 {
   requires com.myproject.module2;
   exports com.myproject.project1;
   exports com.myproject.project2;

Below are some of the module descriptors described:

  • module module. name: declares a module called
  • requires module. name: specifies that our module depends on the module. name, allows this module to access public types exported in the target module.
  • requires a transitive module. name: Any modules that depend on this module automatically depend on
  • exports It says that our module exports public members in package for every module requiring this one.
  • exports to It is the same as above, but limits which modules can use the public members from the package
  • uses class. name: It makes the current module a consumer for service
  • provides with It registers class a service that provides an implementation of the service.
  • opens It allows other modules to use reflection to access the private members of package
  • opens to It does the same, but limits which modules can have reflection access to the private members in the

Updated on: 26-Mar-2020


Kickstart Your Career

Get certified by completing the course

Get Started