When there were duplicate JARs with different versions, the behavior was very inconsistent. Does anyone know how the JVM deals with duplicates?
+10
A:
The classloader searches the classpath in order, and uses the first matching class it finds.
meriton
2009-11-03 18:41:02
In general this is correct. However, it depends on the implementation of the classloader. For example, when loading classes within a web framework the deployed jar/war/ear/sar files may be checked before the official classpath.
Chris Nava
2009-11-03 19:18:12
+3
A:
FWIW, this is an example of a larger topic (modularity) that is addressed by OSGi and Project Jigsaw/JSR 294 in JDK 7.
Your question is good motivation for the topic: the venerable, simple classpath may have been a good idea at its inception, but it is certainly a pain point in today's age of high dependence on 3rd-party-libraries.
Michael Easter
2009-11-03 18:48:20