- Modular Programming in Java 9
- Koushik Kothagal
- 349字
- 2021-07-02 18:38:17
The classpath problem
We've seen two problems in Jack's and Amit's stories. Jack needed an effective way to encapsulate portions of his library, but couldn't. Amit needed a way to ensure reliable execution of his application without actually executing it. Both Jack and Amit didn't really have a solution to their problems because of the way classpath resolution works in Java. We may sometimes mistakenly think of a JAR file as a way to build a reusable module in Java, but that's unfortunately not the case. A JAR file is just a convenient bundle of classes. Nothing more! Once in the classpath, the JVM treats classes in a JAR no differently from separate class files all in the same root directory. At runtime, as far as the JVM is concerned, an application is just a set of classes in a flat list of packages.
What's worse is, once a class is in the classpath, it's free for all. It's incredibly easy for any developer to use a type they are not supposed to, or a type that might be available for them during compile time, but not at deployment/runtime. Or there could be multiple copies or even multiple versions of the same class in two different classpath locations, making it unpredictable which version the runtime will actually pick up during execution. There's a problem commonly called JAR hell, which refers to several issues resulting from mismatched and incorrect classes and versions in JAR files.
This problem is exacerbated in huge code bases with hundreds of thousands of classes. Imagine all those classes in your application as a flat list with no structure! It's a nightmare to maintain and organize. The bigger the code base, the bigger the problem. To illustrate this, let's take the classic example of a code base that's written in Java, that's incredibly large and complex, and has lasted for many years now. It is perhaps one of the oldest Java code bases ever, and still it continues to grow and change at a fairly rapid pace. Any guesses? Well, it's the Java platform itself!
- Software Defined Networking with OpenFlow
- R語言數據分析從入門到精通
- 小程序實戰視頻課:微信小程序開發全案精講
- Django開發從入門到實踐
- 區塊鏈:以太坊DApp開發實戰
- Julia Cookbook
- 3D少兒游戲編程(原書第2版)
- Java應用開發技術實例教程
- SQL Server 2012數據庫管理與開發項目教程
- Visual C#通用范例開發金典
- 前端HTML+CSS修煉之道(視頻同步+直播)
- Android項目實戰:手機安全衛士開發案例解析
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- Swift語言實戰晉級
- FFmpeg開發實戰:從零基礎到短視頻上線