Employ the requires keyword within a module’s module-info.java file to specify dependencies on other modules.
module |
The requires keyword, as a module directive, indicates another module on which the current module relies.
Additionally, two modifiers, transitive and static, can be appended to the requires directive.
The transitive modifier enables other modules to utilize the current module without needing to explicitly declare the same dependency.
The static modifier renders the requirement optional at runtime, allowing the current module to function even if the dependent module is absent.
Note: The requires keyword is a module directive intended for use within a module’s module-info.java file.
The introduction of the requires keyword occurred in Java 9.