Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand java Module Modularization

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to understand java Module modularization, which may not be understood by many people. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Preface

Friends who have seen the knife should know that recently, the knife is writing a desktop toolkit, which can connect to K8s, make a drawing bed, and so on, in which the technology stack is jdk14+javaFX.

JDK14 (Module) + javaFxJDK14 (Module)

JDK14 is chosen mainly because of the jpackage command, which can help us package the java program into exe in win and dmg, pkg in mac. In this way, users no longer need to install jdk/jre separately. With the module of java after java9, the jre can be simplified to the maximum extent. Although it is streamlined, in fact, you can see that every time I send a package in the group, it is still close to 100MB.

JavaFX

Java as a cross-platform language, our more intuitive feeling is to write a springboot program on win/mac, and then throw it to the win/linux server to run. Not only server-side applications, desktop-side applications can also be so cross-platform. With the above applications packaged with jpackage, packages packed on different platforms can be run on different platforms. Although there will be some differences in the display of UI/ characters, the differences are not great. It can be handled through interfaces-classes implemented on different platforms.

System configuration requires java Module

The difference between modularization and non-modularization is the difference between module-info.java in the embodiment of the code.

As shown in the figure above: the key to the file lies in three keywords (requires, opens, export), because our project is already a top-level module, do not need to provide methods for other modules, so do not use the export keyword.

Requires: we need javafx.controls and javafx.fxml modules for this module (module name: red.lixiang.tools.sunflower)

Opens: mainly used for reflection. Javafx.fxml can reflect classes in red.lixiang.tools.sunflower, and then instantiate them or call methods in instances.

Jlink

In java modularization, the jlink command is the core, and its function is to extract the modules we need in jdk, package the modules we introduced ourselves, and then generate an image (runnable image), which is done by gradle plug-ins. We just need to know what this command does, and the generated file is as follows:

We can see the file modules in the lib folder, which is the merged module dependency. at this time, to run this program, just run Sunflower/Sunflower.bat in the bin directory.

The function of jlink, we can use the above picture to show, package the requires of the project into the modules in lib, and package the related commands in jdk into the image folder.

After reading the above, do you have any further understanding of how to understand java Module modularity? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report