Home > Java > javaTutorial > JPMS: Java Platform Module System

JPMS: Java Platform Module System

PHPz
Release: 2023-09-24 17:05:07
forward
1221 people have browsed it

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!

source:tutorialspoint.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template