How can we modify an existing module in Java 9?

The module is a named, self-describing collection of code and data. The code has been organized as a set of packages containing types like Java classes and interfaces. The data includes resources and other kinds of static information. We need to declare a module then add module-info.java at the root of the source code.

Below is the template of the "module-info.java" file.

module  {
   requires  ;
   requires ;

   exports ;
   exports ;

   exports  to 
}

We can use certain command-line options that help us to modify existing modules and add dependencies to them, export additional packages.

Below are the few command-line commands that can be used to modify an existing module.

1) --add-reads =(,)*

The above command can update to read , regardless of the module declaration. can be ALL-UNNAMED to read all nameless modules.

2) --add-exports /=(,)*

The above command can update to export to , regardless of the module declaration. can be ALL-UNNAMED to export to all nameless modules.

3) --add-opens /=(,)*

The above command update  to open to , regardless of the module declaration.

4) --patch-module =(;)*

The above command can replace or increase a module with classes and resources in jar files or directories.

Updated on: 2020-04-10T17:24:53+05:30

606 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements