Java Platform Module System


The Java Platform Module System specifies a distribution format for collections of Java code and associated resources. It also specifies a repository for storing these collections, or modules, and identifies how they can be discovered, loaded and checked for integrity. It includes features such as namespaces with the aim of fixing some of the shortcomings in the existing JAR format, especially the JAR Hell, which can lead to issues such as classpath and class loading problems.
The Java Module System was initially being developed under the Java Community Process as JSR 277 and was scheduled to be released with Java 7.
JSR 277 later was put on hold and Project Jigsaw was created to modularize the JDK. This JSR was superseded by JSR 376.
Project Jigsaw was originally intended for Java 7 but was deferred to Java 8 as part of Plan B, and again deferred to a Java 9 release in 2017. Java 9 including the Java Module System was released on September 21, 2017.

Architecture

The Java Module System implemented for Java 9 include the following JEPs and JSR :
Additionally, several other JDK 9 features have been added to ease transition to the module system:
Modules are a new way of grouping code and data. Contrary to Jar files, modules explicitly declare which modules they depend on, and what packages they export.
For example, the following module declaration declares that the module com.foo.bar depends on another com.foo.baz module, and exports the following packages: com.foo.bar.alpha and com.foo.bar.beta:

module com.foo.bar

Contrary to the Jar file format, the module will describe these dependencies in a module declaration which will be placed in a file named module-info.java at the root of the module’s source-file hierarchy. The JDK will be able to check them both at compile-time and runtime. The JDK itself will be modularized for Java 9.

Links with OSGi

The Java Module System does not intend to support all the functionalities that the OSGi platform currently supports. However the Java Module System will support functions which are not supported by OSGi, such as modularity at compile-time, and built-in support for native libraries. A couple of articles exploring how the Java Module System and OSGi could interoperate were published in 2016. These can be found on InfoQ and also the OSGi Alliance Blog.