search
HomeJavajavaTutorialJPMS: Java Platform Module System

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

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
This article is reproduced at:tutorialspoint. If there is any infringement, please contact admin@php.cn delete
How does platform independence benefit enterprise-level Java applications?How does platform independence benefit enterprise-level Java applications?May 03, 2025 am 12:23 AM

Java is widely used in enterprise-level applications because of its platform independence. 1) Platform independence is implemented through Java virtual machine (JVM), so that the code can run on any platform that supports Java. 2) It simplifies cross-platform deployment and development processes, providing greater flexibility and scalability. 3) However, it is necessary to pay attention to performance differences and third-party library compatibility and adopt best practices such as using pure Java code and cross-platform testing.

What role does Java play in the development of IoT (Internet of Things) devices, considering platform independence?What role does Java play in the development of IoT (Internet of Things) devices, considering platform independence?May 03, 2025 am 12:22 AM

JavaplaysasignificantroleinIoTduetoitsplatformindependence.1)Itallowscodetobewrittenonceandrunonvariousdevices.2)Java'secosystemprovidesusefullibrariesforIoT.3)ItssecurityfeaturesenhanceIoTsystemsafety.However,developersmustaddressmemoryandstartuptim

Describe a scenario where you encountered a platform-specific issue in Java and how you resolved it.Describe a scenario where you encountered a platform-specific issue in Java and how you resolved it.May 03, 2025 am 12:21 AM

ThesolutiontohandlefilepathsacrossWindowsandLinuxinJavaistousePaths.get()fromthejava.nio.filepackage.1)UsePaths.get()withSystem.getProperty("user.dir")andtherelativepathtoconstructthefilepath.2)ConverttheresultingPathobjecttoaFileobjectifne

What are the benefits of Java's platform independence for developers?What are the benefits of Java's platform independence for developers?May 03, 2025 am 12:15 AM

Java'splatformindependenceissignificantbecauseitallowsdeveloperstowritecodeonceandrunitonanyplatformwithaJVM.This"writeonce,runanywhere"(WORA)approachoffers:1)Cross-platformcompatibility,enablingdeploymentacrossdifferentOSwithoutissues;2)Re

What are the advantages of using Java for web applications that need to run on different servers?What are the advantages of using Java for web applications that need to run on different servers?May 03, 2025 am 12:13 AM

Java is suitable for developing cross-server web applications. 1) Java's "write once, run everywhere" philosophy makes its code run on any platform that supports JVM. 2) Java has a rich ecosystem, including tools such as Spring and Hibernate, to simplify the development process. 3) Java performs excellently in performance and security, providing efficient memory management and strong security guarantees.

How does the JVM contribute to Java's 'write once, run anywhere' (WORA) capability?How does the JVM contribute to Java's 'write once, run anywhere' (WORA) capability?May 02, 2025 am 12:25 AM

JVM implements the WORA features of Java through bytecode interpretation, platform-independent APIs and dynamic class loading: 1. Bytecode is interpreted as machine code to ensure cross-platform operation; 2. Standard API abstract operating system differences; 3. Classes are loaded dynamically at runtime to ensure consistency.

How do newer versions of Java address platform-specific issues?How do newer versions of Java address platform-specific issues?May 02, 2025 am 12:18 AM

The latest version of Java effectively solves platform-specific problems through JVM optimization, standard library improvements and third-party library support. 1) JVM optimization, such as Java11's ZGC improves garbage collection performance. 2) Standard library improvements, such as Java9's module system reducing platform-related problems. 3) Third-party libraries provide platform-optimized versions, such as OpenCV.

Explain the process of bytecode verification performed by the JVM.Explain the process of bytecode verification performed by the JVM.May 02, 2025 am 12:18 AM

The JVM's bytecode verification process includes four key steps: 1) Check whether the class file format complies with the specifications, 2) Verify the validity and correctness of the bytecode instructions, 3) Perform data flow analysis to ensure type safety, and 4) Balancing the thoroughness and performance of verification. Through these steps, the JVM ensures that only secure, correct bytecode is executed, thereby protecting the integrity and security of the program.

See all articles

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 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool