How can we modify an existing module in Java 9?

JavaObject Oriented ProgrammingProgramming

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 <module-name> {
   requires <module-name1> ;
   requires <module-name2>;

   exports <package-name1>;
   exports <package-name2>;

   exports <package-name> to <module-name>
}

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 <module>=<target-module>(,<target-module>)*

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

2) --add-exports <module>/<package>=<target-module>(,<target-module>)*

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

3) --add-opens <module>/<package>=<target-module>(,<target-module>)*

The above command update <module> to open <package> to <target-module>, regardless of the module declaration.

4) --patch-module <module>=<file>(;<file>)*

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

raja
Published on 10-Apr-2020 20:54:53
Advertisements