Java class loader: Difference between revisions

Content deleted Content added
Line 6:
 
The classloading process is fairly complicated, and is the subject of much confusion in [[software deployment]] and [[Software development|development]]. Java programs may make use of external or [[third party library|third party libraries]] (that is, libraries written and provided by someone other than the author of the program) or may itself be composed, at least in part, by a number of libraries.
 
== JAR hell ==
 
'''Jar hell''' is a general term used to describe all the various ways in which the classloading process can end up not working.
 
* One case is when a developer or deployer of a [[Java application]] has accidentally made two different versions of a library available to the system. This is not considered an [[error]] by the system. Rather, the system will load classes from one or the other library. So, a developer who thinks she has replaced a library with a new version, but who has instead simply added the new library to the list of available libraries, may be surprised to see the application still behaving as though the old library is in use, which of course, it may well be.
 
* Another version of the problem arises when two libraries (or a library and the application) require different versions of the same third library. Without taking extraordinary measures (which may or may not even be available, depending on the circumstances) there is no way to load both versions of the third library.
 
* The most complex ''Jar hell'' problems arise in circumstances that take advantage of the full complexity of the classloading system. A Java program is not required to use only a single "flat" classloader, but instead may be composed of several (an indefinite number, in fact) nested, cooperating classloaders. This is not as uncommon as one might think: so-called "[[servlet]] containers" are typically implemented in terms of multiple classloaders. The interactions between classloaders is too complex to be fully described here. It is sufficient to say that classes loaded by different classloaders interact in ways which may not be fully comprehended by the developer, leading to inexplicable errors or bugs.