The Java class loader is written in Java. It is therefore possible to create a custom class loader without understanding the finer details of the Java Virtual Machine. Apart from the Bootstrap class loader, every Java class loader has a parent class loader.12 The parent class loader is defined when a new class loader is instantiated or set to the virtual machine's system default class loader.
This makes it possible (for example):
Jakarta EE (formerly Java EE and J2EE) application servers typically load classes from a deployed WAR or EAR archive by a tree of class loaders, isolating the application from other applications, but sharing classes between deployed modules. So-called "servlet containers" are typically implemented in terms of multiple class loaders.1415
JAR hell is a term similar to DLL hell used to describe all the various ways in which the classloading process can end up not working.16 Three ways JAR hell can occur are:
The OSGi Alliance specified (starting as JSR 8 in 1998) a modularity framework that aims to solve JAR hell for current and future VMs in ME, SE, and EE that is widely adopted. Using metadata in the JAR manifest, JAR files (called bundles) are wired on a per-package basis. Bundles can export packages, import packages and keep packages private, providing the basic constructs of modularity and versioned dependency management.
Java 9 introduced the Java Platform Module System in 2017. This specifies a distribution format for collections of Java code and associated resources. It also specifies a repository for storing these collections, or modules, and identifies how they can be discovered, loaded and checked for integrity. It includes features such as namespaces with the aim of fixing some of the shortcomings in the existing JAR format. The Java Platform Module System follows a different philosophy from the OSGi architecture that aims at providing modularity for the Java Runtime Environment in a backwards-compatible way that uses the default mechanism of loading classes that the JRE provides. However, since the Java Platform Module System does not offer the ability for controlled co-existence of libraries with different versions, it does not fully address the JAR hell problem.18
Mcmanis, Chuck (October 1, 1996). "The basics of Java class loaders". JavaWorld. Retrieved 2020-07-13. https://www.infoworld.com/article/2077260/learn-java-the-basics-of-java-class-loaders.html ↩
Horstmann 2022, §10.1.1 The Class-Loading Process. - Horstmann, Cay (April 15, 2022). Core Java. Oracle Press Java. ISBN 0-13-787107-4. ↩
Horstmann 2022, §8.2.5 Writing Byte Codes to Memory. - Horstmann, Cay (April 15, 2022). Core Java. Oracle Press Java. ISBN 0-13-787107-4. ↩
Christudas, Binildas (January 26, 2005). "Internals of Java Class Loading". onjava.com. Archived from the original on 2018-05-10. https://web.archive.org/web/20180510223447/http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html ↩
"Understanding Extension Class Loading". The Java Tutorials. docs.oracle.com. Retrieved 2020-07-13. https://docs.oracle.com/javase/tutorial/ext/basics/load.html ↩
Sosnoski, Dennis (April 29, 2003). "Classes and class loading". IBM DeveloperWorks. Retrieved 2008-01-26. http://www.ibm.com/developerworks/java/library/j-dyn0429/ ↩
These libraries are stored in Jar files called rt.jar, core.jar, server.jar, etc. /wiki/JAR_(file_format) ↩
Horstmann 2022, 10.1.2 The Class Loader Hierarchy. - Horstmann, Cay (April 15, 2022). Core Java. Oracle Press Java. ISBN 0-13-787107-4. ↩
Roubtsov, Vladimir (May 9, 2003). "Cracking Java byte-code encryption". JavaWorld. Retrieved 2020-07-13. https://www.infoworld.com/article/2077342/cracking-java-byte-code-encryption.html ↩
deBoer, Tim; Karasiuk, Gary (August 21, 2002). "J2EE Class Loading Demystified". IBM DeveloperWorks. Retrieved 2008-01-26. https://www.ibm.com/developerworks/websphere/library/techarticles/0112_deboer/deboer.html ↩
"Depot - Apache Incubator". Archived from the original on 2013-06-01. https://web.archive.org/web/20130601002059/http://incubator.apache.org/depot/version/jar-hell.html ↩
"Taxonomy of class loader problems with Jakarta Commons Logging". http://articles.qos.ch/classloader.html ↩
Bartlett, Neil; Hackbarth, Kai (2016-09-22). "Java 9, OSGi and the Future of Modularity (Part 1)". InfoQ. https://www.infoq.com/articles/java9-osgi-future-modularity/#1 ↩