官术网_书友最值得收藏!

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!

主站蜘蛛池模板: 高台县| 石棉县| 宁城县| 恩施市| 邹平县| 获嘉县| 宜宾市| 沂南县| 湖北省| 东乌珠穆沁旗| 广宁县| 石城县| 土默特左旗| 阜新| 临泉县| 怀柔区| 永州市| 疏勒县| 双峰县| 南川市| 肇州县| 阿坝县| 阿坝| 邵阳市| 平湖市| 龙胜| 赤水市| 桦甸市| 广东省| 会泽县| 阿克苏市| 亳州市| 海晏县| 凤山市| 八宿县| 砚山县| 三江| 吉林省| 云霄县| 宿松县| 喀什市|