MarketJava Platform Module System
Company Profile

Java Platform Module System

The Java Platform Module System (JPMS) 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.

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{{cite web • JSR 376: Java Platform Module System{{cite web 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.{{cite web • JEP 253: Prepare JavaFX 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.{{cite web • 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.{{cite web • 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.{{cite web == Properties of modules ==
Properties of modules
Modules are used to group packages and tightly control what packages belong to the public API. Contrary to Jar files, modules explicitly declare which modules they depend on, and what packages they export. The JDK itself has been modularized in Java 9. For example, the majority of the Java standard library is exported by the module java.base. As of Java 25, modules can themselves be imported, automatically importing all exported packages. This is done using import module. For example, import module java.sql; is equivalent to import java.sql.*; import javax.sql.*; // Remaining indirect exports from java.logging, java.transaction.xa, and java.xml Similarly, import module java.base;, similarly, imports all 54 packages belonging to java.base. package org.wikipedia.examples; import module java.base; /** * Importing module java.base allows us to avoid manually importing most classes * The following classes (outside of java.lang) are used: * - java.text.MessageFormat * - java.util.Date * - java.util.List * - java.util.concurrent.ThreadLocalRandom */ public class Example { public static void main(String[] args) { List colours = List.of("Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"); IO.println(MessageFormat.format("My favourite colour is {0} and today is {1,date,long}", colours.get(ThreadLocalRandom.current().nextInt(colours.size())), new Date() )); } } Modules use the following keywords: • exports: used in a module declaration to specify which packages are available to other modules • module: declares a module • open: indicates that all classes in a package are accessible via reflection by other modules • opens: used to open a specific package for reflection to other modules • provides: used to declare that a module provides an implementation of a service interface • requires: used in a module declaration to specify that the module depends on another module • to: used with the opens directive to specify which module is allowed to reflectively access the package • transitive: used with the requires directive to indicate that a module not only requires another module but also makes that module's dependencies available to modules that depend on it • uses: used in a module to declare that the module is using a service (i.e. it will consume a service provided by other modules) • with: used with the provides directive to specify which implementation of a service is provided by the module == Standard modules ==
Standard modules
Core modules The modules under namespace java.* belong to the Java Platform, Standard Edition, and modules under namespace jdk.* belong to the Java Development Kit. The module jdk.unsupported is not an official module, but often bundled with the JDK, representing implementation details in the Java standard library. It contains packages in namespace sun.* (which contains the sun.misc.Unsafe class, used to manipulate the CPU and hardware, directly manage memory, and other things) and com.sun.* packages. module jdk.unsupported { exports sun.misc; exports sun.reflect; exports com.sun.nio.file; opens sun.misc; opens sun.reflect; } Jakarta EE, formerly part of the Java standard library, is not modularised, however build systems can generate automatic modules for it. JavaFX modules JavaFX was previously bundled with the core JDK, until Java 11 when it was split into OpenJFX. JavaFX is split into the following modules. == Links with OSGi ==
Links with OSGi
The Java Module System does not intend to support all the functionalities that the OSGi 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.{{cite web == See also ==
tickerdossier.comtickerdossier.substack.com