Table of Contents
Why does Java need modules?
Class path VS module path
Modules in JAVA
Backwards Compatibility
Common mistakes
in conclusion
Home Java javaTutorial JPMS: Java Platform Module System

JPMS: Java Platform Module System

Sep 24, 2023 pm 05:05 PM

JPMS stands for Java Platform Module System. This is a new feature in Java 9. Our java applications and Java packages can be packaged into Java modules with the help of the Java module system. Java modules allow us to specify which packages of the module and other Java modules should be able to see it. Java module also lists the Java modules required for it to run.

Java Platform System is also known as Java Jigsaw or Project Jigsaw. The name Jigsaw was used at the time of its development. The main purpose of developing this is to make the JRE more modular. JPMS solves several major problems, namely Classpath/JAR Hell, large-scale single JDK, version conflicts, and security issues.

Now, let’s delve deeper into the Java platform modular systems to learn more about them.

Why does Java need modules?

It is important to remember that JPMS is an SE (Standard Edition) feature and affects all levels of Java. Nonetheless, the purpose of this patch is to enable most programs to run without modification when switching from Java 8 to Java 9. Its main purpose is to collect relevant packages visible to the module while hiding some components from external users of the module.

JPMS was launched with the following stated objectives -

  • Easily organize large applications and libraries.

  • Improve security

  • Improve application performance

  • Platform failure for managing small devices.

  • Improve structure.

Class path VS module path

To date, the classpath has been the primary determinant of what a program can access when executing in Java. Despite playing this role and being clearly understood, the classpath ends up becoming one big, undifferentiated bucket into which all dependencies are plugged.

The module path adds one level above the classpath. It acts as a storage space for packages and selects which packages an application can access.

Classpath

Module path

Applies to all Java versions

Only applicable to Java 9 and above

No need module-info.java

Do you need module-info.java

Adding the library is only effective if the project does not have module-info.java

The library can work without module-info.java

Add non-modular libraries only

Both modular and non-modular can be added

Weak encapsulation and abstraction

Strong encapsulation and abstraction

Weak modularity

Very modular

Cannot add a library to a project by adding part of it to the classpath

We can only add the required parts of the library to the project by adding it to the module path

Modules in JAVA

JDK is composed of modules. If you are using the JDK on your system, you also have the source code. If you didn't know this, check this out to learn more.

There is a /lib directory in the JDK installation directory. In this directory you will find a src.zip file. Then extract it into the /src directory. After that look in /src directory and find /java.base directory then you will find module-info.java file and finally open it.

After the Javadoc comments at the top, you will find a folder called modulesection.base, followed by the export line. The format is a bit esoteric, so we won’t get too deep into it.

As you can see, the java.base module exports several well-known Java packages, including java.io. This is how the module that collects packages works.

JPMS:Java 平台模块系统

The requirements of the

directive are opposite to those of export. Therefore, the specified module may require a module. Specify the module path in the same way you provide the classpath when running the Java compiler against the module. This makes it possible to resolve dependencies.

Backwards Compatibility

Java 9 was created with backward compatibility in mind. However, the new module structure is a major shift and you may run into issues, especially in large codebases.

The following command may be useful in troubleshooting issues originating from the codebase - when the command jdeps points to a class, it will look for any dependencies and the modules that require the dependencies.

If your dependencies are causing problems, you may wish to build with a newer version of the package you depend on that is compatible with Java 9. If not, you may want to look for options.

Common mistakes

How to solve java.lang.NoClassDefFoundError -

Javax/xml/bind/JAXBException
Copy after login

This is the code complaining that the assigned class cannot be found because it has been migrated to a module and is not visible to the consuming code. There are several solutions.

JPMS is a pretty significant transition, so adoption will take some time. Fortunately, since Java 8 is a long-term support release, there is no immediate need.

However, in the long run, it will be necessary for old projects to be migrated, and for new projects to use modules wisely, in order to perhaps gain some of the benefits already given.

in conclusion

JPMS stands for Java Platform Module System and was also called project jigsaw in the early stages of development. It makes it easier for developers to organize large applications and libraries. It improves the structure and increases the security level of the platform. It is also used to improve application performance and is useful for platform decomposition for smaller devices. The main idea behind this is to enable a collection of related packages visible to the module, while hiding elements from external consumers on the module.

The above is the detailed content of JPMS: Java Platform Module System. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1653
14
PHP Tutorial
1251
29
C# Tutorial
1224
24
Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

How do I convert names to numbers to implement sorting and maintain consistency in groups? How do I convert names to numbers to implement sorting and maintain consistency in groups? Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

How to elegantly obtain entity class variable names to build database query conditions? How to elegantly obtain entity class variable names to build database query conditions? Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How to simplify field mapping issues in system docking using MapStruct? How to simplify field mapping issues in system docking using MapStruct? Apr 19, 2025 pm 06:21 PM

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to safely convert Java objects to arrays? How to safely convert Java objects to arrays? Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to use the Redis cache solution to efficiently realize the requirements of product ranking list? How to use the Redis cache solution to efficiently realize the requirements of product ranking list? Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

See all articles