Java Module System
   HOME

TheInfoList



OR:

The Java Platform Module System specifies a distribution format for collections of
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mos ...
code and associated resources. It also specifies a repository for storing these collections, or ''
modules Broadly speaking, modularity is the degree to which a system's components may be separated and recombined, often with the benefit of flexibility and variety in use. The concept of modularity is used primarily to reduce complexity by breaking a s ...
'', 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 A jar is a rigid, cylindrical or slightly conical container, typically made of glass, ceramic, or plastic, with a wide mouth or opening that can be closed with a lid, screw cap, lug cap, cork stopper, roll-on cap, crimp-on cap, press-on c ...
format, especially the
JAR Hell The Java Class Loader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. Usually classes are only loaded on demand. The Java run time system does not need to know about files and file sys ...
, 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 The Java Community Process (JCP), established in 1998, is a formalized mechanism that allows interested parties to develop standard technical specifications for Java technology. Anyone can become a JCP Member by filling a form available at thJCP w ...
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 (Java Platform Module System). Project Jigsaw was originally intended for Java 7 (2011) but was deferred to Java 8 (2014) 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 in Java 9 includes the following JEPs and JSR (Java Specification Request): * JEP 200: The Modular JDK: Define a modular structure for the JDK * JEP 201: Modular Source Code: Reorganize the JDK source code into modules, enhance the build system to compile modules, and enforce module boundaries at build time * JEP 220: Modular Run-Time Images: Restructure the JDK and JRE run-time images to accommodate modules and to improve performance, security, and maintainability * JEP 261: Module System: Implement the Java Platform Module System * JEP 282: The Java Linker: Create a tool that can assemble and optimize a set of modules and their dependencies into a custom run-time image * JSR 376: Java Platform Module System Additionally, several other JDK 9 features have been added to ease transition to the module system: * JEP 238: Multi-Release JAR Files: Extend the JAR file format to allow multiple, Java-release-specific versions of class files to coexist in a single archive. * JEP 253: Prepare
JavaFX JavaFX is a software platform for creating and delivering desktop applications, as well as rich web applications that can run across a wide variety of devices. JavaFX has support for desktop computers and web browsers on Microsoft Windows, Linu ...
UI Controls & CSS APIs for Modularization: Define public APIs for the JavaFX functionalities that is presently only available via internal APIs and would become inaccessible due to modularization. * JEP 260: Encapsulate Most Internal APIs: Make most of the JDK's internal APIs inaccessible by default but leave a few critical, widely-used internal APIs accessible, until supported replacements exist for all or most of their functionality. * JEP 275: Modular Java Application Packaging: The Java packager will evolve for JDK 9, making it aware of modules, allowing for example to package a module and all the modules it depends on.


Properties of modules

Modules are a new way of grouping code. Contrary to Jar files, modules explicitly declare which modules they depend on, and what packages they export. Explicit dependency declarations improve the integrity of the code, by making it easier to reason about large applications and the dependencies between software components. The module declaration is placed in a file named ''module-info.java'' at the root of the module’s source-file hierarchy. The JDK will verify dependencies and interactions between modules both at compile-time and runtime. 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 
The public members of ''com.foo.bar.alpha'' and ''com.foo.bar.beta'' packages will be accessible by dependent modules. Private members are inaccessible even through a means such as
reflection Reflection or reflexion may refer to: Science and technology * Reflection (physics), a common wave phenomenon ** Specular reflection, reflection from a smooth surface *** Mirror image, a reflection in a mirror or in water ** Signal reflection, in ...
. Note that in Java versions 9 through 16, whether such 'illegal access' is ''de facto'' permitted depends on a command line setting. The JDK itself has been modularized in Java 9.


Links with OSGi

The Java Module System does not intend to support all the functionalities that the
OSGi OSGi is an open specification and open source project under the Eclipse Foundation. It is a continuation of the work done by the OSGi Alliance (formerly known as the Open Services Gateway initiative), which was an open standards organization fo ...
platform currently supports (for example the Life-Cycle model and the Services Registry). 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.


See also

*
Java package A Java package organizes Java classes into namespaces, providing a unique namespace for each type it contains. Classes in the same package can access each other's package-private and protected members. In general, a package can contain the follo ...
*
Classpath (Java) Classpath is a parameter in the Java Virtual Machine or the Java compiler that specifies the location of user-defined classes and packages. The parameter may be set either on the command-line, or through an environment variable. Overview and ...
*
Java Classloader The Java Class Loader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. Usually classes are only loaded on demand. The Java run time system does not need to know about files and file syste ...


References


External links


JSR 277

JSR 294

JSR 376

Project Jigsaw

The State of the Module System

Java Platform Module System: Issue Summary
{{Java (software platform) Java specification requests