Module Descriptor (module-info.java)

module-info.java is an important file in the modular system, and it contains modular metadata which describes the behavior module. It is a Java file, but it is not like a traditional Java file. It has its own syntax and it's compiled into the module-info.class file.

The following is the syntax that we have to follow when creating module-info.java:

module <module-name> {       requires <module-name-1>;       requires <module-name-2>;               .               .       requires <module-name-n>;       exports <package-1>;               .               .       exports <package-n>;}

The following is an example of the module-info.java file, where each module contains a unique ID and optional module descriptor details:

module com.packt.java9dependency.chapter2 { exports com.packt.java9dependency.chapter2.services; ...

Get Java 9 Dependency Injection now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.