亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄
Why Was Project Jigsaw Needed?
Key Components of the Java Module System
Evolution and Adoption Timeline
Practical Benefits for Developers
1. Smaller Runtime Images with jlink
2. Improved Security and Maintainability
3. Clearer Dependencies
4. Better Tooling and Diagnostics
Challenges and Criticisms
Modern Usage and Best Practices
Conclusion
首頁(yè) Java java教程 Java模塊系統(tǒng)的演變(Project Jigsaw)

Java模塊系統(tǒng)的演變(Project Jigsaw)

Jul 30, 2025 am 12:35 AM
java 模組化

Java的模塊系統(tǒng)(Project Jigsaw)從Java 9開(kāi)始引入,旨在解決類(lèi)路徑機(jī)制帶來(lái)的封裝性差、依賴混亂、JDK臃腫等問(wèn)題。 1. 它通過(guò)module-info.java文件定義模塊名稱(chēng)、依賴關(guān)係、導(dǎo)出包和服務(wù),實(shí)現(xiàn)強(qiáng)封裝和可靠配置;2. java.base作為所有模塊的基礎(chǔ),內(nèi)部包如jdk.internal.*默認(rèn)不可訪問(wèn);3. 開(kāi)發(fā)者可使用jlink創(chuàng)建僅包含所需模塊的精簡(jiǎn)運(yùn)行時(shí),減小部署體積;4. 模塊化提升了安全性、可維護(hù)性和依賴清晰度,但遷移舊項(xiàng)目存在反射受限、拆分包衝突等挑戰(zhàn);5. 儘管存在學(xué)習(xí)曲線和兼容性問(wèn)題,現(xiàn)代Java開(kāi)發(fā)應(yīng)優(yōu)先採(cǎi)用模塊化設(shè)計(jì),結(jié)合jlink部署,並避免在生產(chǎn)環(huán)境中使用--add-opens或--illegal-access,以確保系統(tǒng)穩(wěn)健性和安全性。該系統(tǒng)已深刻影響Java應(yīng)用的運(yùn)行方式,成為構(gòu)建可擴(kuò)展、安全、高效系統(tǒng)的必備基礎(chǔ)。

The Evolution of the Java Module System (Project Jigsaw)

Java's module system, better known as Project Jigsaw , was a long-awaited addition to the Java platform that fundamentally changed how Java applications are structured, especially starting with Java 9 . Its evolution was driven by the need to scale the JDK and large applications in a more maintainable, secure, and performant way. Here's a breakdown of its journey, purpose, and impact.

The Evolution of the Java Module System (Project Jigsaw)

Why Was Project Jigsaw Needed?

Before Java 9, Java relied on the classpath mechanism to locate and load classes at runtime. While simple, this model had several drawbacks:

  • No encapsulation at the package level : All public classes were accessible, even if they weren't meant for external use (eg, internal JDK APIs like sun.misc.Unsafe ).
  • "JAR Hell" : Conflicts from duplicate class names across JARs, unclear dependencies, and circular dependencies were common.
  • Monolithic JDK : The entire JDK was bundled together—even if an app used only a small part, the whole runtime had to be shipped.
  • Poor scalability : Large applications became harder to maintain due to unclear dependency graphs and lack of structure.

Project Jigsaw aimed to solve these by introducing a module system —a way to group packages into named, self-describing modules with explicit dependencies.

The Evolution of the Java Module System (Project Jigsaw)

Key Components of the Java Module System

The module system introduced several core concepts:

  • Module : A named collection of packages with a module-info.java file that declares:
    • The module's name
    • Which packages it exports (makes publicly available)
    • Which other modules it requires
    • Services it uses or provides
 // Example: module-info.java
module com.example.myapp {
    requires java.base;
    requires java.logging;
    exports com.example.myapp.api;
}
  • java.base module : The foundational module. Every module implicitly depends on it.
  • Strong encapsulation : Only exported packages are accessible. Internal packages (eg, jdk.internal.* ) are now truly hidden.
  • Reliable configuration : The JVM validates the entire module graph at startup, detecting missing or conflicting modules early.

Evolution and Adoption Timeline

Version Milestone
Java 7 (2011) Project Jigsaw started, initially planned for Java 7 but deferred.
Java 8 (2014) Delayed again—focus shifted to lambdas and streams.
Java 9 (2017) Module system officially launched . JDK itself modularized into ~90 modules.
Java 11 (2018–present) Modules matured. Tools like jlink allow creating custom runtime images. Spring, Jakarta EE, and other frameworks adapted.
Java 16 Strong encapsulation enforced by default (use --illegal-access=deny to block reflection on internal APIs).

Practical Benefits for Developers

You can now build a minimal JRE containing only the modules your app needs:

The Evolution of the Java Module System (Project Jigsaw)
 jlink --module-path $JAVA_HOME/jmods:myapp.jar \
      --add-modules com.example.myapp \
      --output myruntime

This reduces container sizes and attack surface—ideal for microservices.

2. Improved Security and Maintainability

By restricting access to internal APIs, the module system prevents accidental (or malicious) use of unstable JDK internals.

3. Clearer Dependencies

Modules make dependencies explicit. No more guessing which libraries a component needs.

4. Better Tooling and Diagnostics

Tools like jdeps analyze dependencies and suggest module configurations:

 jdeps --module-path lib/ --require-recursive myapp.jar

Challenges and Criticisms

Despite its benefits, adoption hasn't been universal:

  • Migration complexity : Large legacy apps using classpath and reflection (eg, OSGi, Spring ClassPathXmlApplicationContext) faced breakage.
  • Split packages : Two modules can't export the same package—common in older libraries.
  • Reflection restrictions : Code that relied on accessing internal JDK APIs (eg, for performance tricks) now fails unless --add-opens is used.
  • Learning curve : Understanding requires , exports , opens , uses , and provides takes time.

Modern Usage and Best Practices

Even if you don't write module-info.java files, the module system affects you:

  • Unnamed modules : JARs on the classpath become "unnamed modules" and can read all named modules—but they export nothing.
  • Automatic modules : JARs on the module path with no module-info are treated as modules with implied names and exports.
  • Hybrid approach : Many apps still use the classpath, but benefit from strong encapsulation in the JDK.

Best practices :

  • Use modules for new projects when possible.
  • Prefer jlink for production deployments.
  • Avoid --add-opens and --illegal-access in production.
  • Keep internal APIs truly internal.

Conclusion

Project Jigsaw wasn't just a feature—it was a platform overhaul . It made Java more modular, secure, and scalable for modern development, especially in cloud-native environments. While adoption has been gradual and sometimes painful, the benefits in reliability, performance, and deployment efficiency are clear.

For developers, understanding the module system is now essential—not just for using the latest Java features, but for building robust, maintainable systems.

Basically, if you're shipping Java apps today, the module system is already shaping how your code runs—whether you see it or not.

以上是Java模塊系統(tǒng)的演變(Project Jigsaw)的詳細(xì)內(nèi)容。更多資訊請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開(kāi)發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺(jué)化網(wǎng)頁(yè)開(kāi)發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)程式碼編輯軟體(SublimeText3)

熱門(mén)話題

Laravel 教程
1597
29
PHP教程
1488
72
VSCODE設(shè)置。 JSON位置 VSCODE設(shè)置。 JSON位置 Aug 01, 2025 am 06:12 AM

settings.json文件位於用戶級(jí)或工作區(qū)級(jí)路徑,用於自定義VSCode設(shè)置。 1.用戶級(jí)路徑:Windows為C:\Users\\AppData\Roaming\Code\User\settings.json,macOS為/Users//Library/ApplicationSupport/Code/User/settings.json,Linux為/home//.config/Code/User/settings.json;2.工作區(qū)級(jí)路徑:項(xiàng)目根目錄下的.vscode/settings

如何使用JDBC處理Java的交易? 如何使用JDBC處理Java的交易? Aug 02, 2025 pm 12:29 PM

要正確處理JDBC事務(wù),必須先關(guān)閉自動(dòng)提交模式,再執(zhí)行多個(gè)操作,最後根據(jù)結(jié)果提交或回滾;1.調(diào)用conn.setAutoCommit(false)以開(kāi)始事務(wù);2.執(zhí)行多個(gè)SQL操作,如INSERT和UPDATE;3.若所有操作成功則調(diào)用conn.commit(),若發(fā)生異常則調(diào)用conn.rollback()確保數(shù)據(jù)一致性;同時(shí)應(yīng)使用try-with-resources管理資源,妥善處理異常並關(guān)閉連接,避免連接洩漏;此外建議使用連接池、設(shè)置保存點(diǎn)實(shí)現(xiàn)部分回滾,並保持事務(wù)盡可能短以提升性能。

在Java的掌握依賴注入春季和Guice 在Java的掌握依賴注入春季和Guice Aug 01, 2025 am 05:53 AM

依賴性(di)IsadesignpatternwhereObjectsReceivedenciesenciesExtern上,推廣looseSecouplingAndEaseerTestingThroughConstructor,setter,orfieldInjection.2.springfraMefringframeWorkSannotationsLikeLikeLike@component@component,@component,@service,@autowiredwithjava-service和@autowiredwithjava-ligatiredwithjava-lase-lightike

Python Itertools組合示例 Python Itertools組合示例 Jul 31, 2025 am 09:53 AM

itertools.combinations用於生成從可迭代對(duì)像中選取指定數(shù)量元素的所有不重複組合(順序無(wú)關(guān)),其用法包括:1.從列表中選2個(gè)元素組合,如('A','B')、('A','C')等,避免重複順序;2.對(duì)字符串取3個(gè)字符組合,如"abc"、"abd",適用於子序列生成;3.求兩數(shù)之和等於目標(biāo)值的組合,如1 5=6,簡(jiǎn)化雙重循環(huán)邏輯;組合與排列的區(qū)別在於順序是否重要,combinations視AB與BA為相同,而permutations視為不同;

故障排除常見(jiàn)的java`ofmemoryError`場(chǎng)景'' 故障排除常見(jiàn)的java`ofmemoryError`場(chǎng)景'' Jul 31, 2025 am 09:07 AM

java.lang.OutOfMemoryError:Javaheapspace表示堆內(nèi)存不足,需檢查大對(duì)象處理、內(nèi)存洩漏及堆設(shè)置,通過(guò)堆轉(zhuǎn)儲(chǔ)分析工具定位並優(yōu)化代碼;2.Metaspace錯(cuò)誤因類(lèi)元數(shù)據(jù)過(guò)多,常見(jiàn)於動(dòng)態(tài)類(lèi)生成或熱部署,應(yīng)限制MaxMetaspaceSize並優(yōu)化類(lèi)加載;3.Unabletocreatenewnativethread因係統(tǒng)線程資源耗盡,需檢查線程數(shù)限制、使用線程池、調(diào)整棧大??;4.GCoverheadlimitexceeded指GC頻繁但回收少,應(yīng)分析GC日誌,優(yōu)化

Python Pytest夾具示例 Python Pytest夾具示例 Jul 31, 2025 am 09:35 AM

fixture是用於為測(cè)試提供預(yù)設(shè)環(huán)境或數(shù)據(jù)的函數(shù),1.使用@pytest.fixture裝飾器定義fixture;2.在測(cè)試函數(shù)中以參數(shù)形式註入fixture;3.yield之前執(zhí)行setup,之後執(zhí)行teardown;4.通過(guò)scope參數(shù)控製作用域,如function、module等;5.將共用fixture放在conftest.py中實(shí)現(xiàn)跨文件共享,從而提升測(cè)試的可維護(hù)性和復(fù)用性。

了解Java虛擬機(jī)(JVM)內(nèi)部 了解Java虛擬機(jī)(JVM)內(nèi)部 Aug 01, 2025 am 06:31 AM

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa

如何使用Java的日曆? 如何使用Java的日曆? Aug 02, 2025 am 02:38 AM

使用java.time包中的類(lèi)替代舊的Date和Calendar類(lèi);2.通過(guò)LocalDate、LocalDateTime和LocalTime獲取當(dāng)前日期時(shí)間;3.使用of()方法創(chuàng)建特定日期時(shí)間;4.利用plus/minus方法不可變地增減時(shí)間;5.使用ZonedDateTime和ZoneId處理時(shí)區(qū);6.通過(guò)DateTimeFormatter格式化和解析日期字符串;7.必要時(shí)通過(guò)Instant與舊日期類(lèi)型兼容;現(xiàn)代Java中日期處理應(yīng)優(yōu)先使用java.timeAPI,它提供了清晰、不可變且線

See all articles