Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does JVM deal with duplicate JARs of different versions

Tags:

java

When there were duplicate JARs with different versions, the behavior was very inconsistent. Does anyone know how the JVM deals with duplicates?

like image 369
Vishal Avatar asked Nov 03 '09 18:11

Vishal


2 Answers

The classloader searches the classpath in order, and uses the first matching class it finds.

like image 91
meriton Avatar answered Nov 08 '22 18:11

meriton


FWIW, this is an example of a larger topic (modularity) that is addressed by OSGi and Project Jigsaw/JSR 294 in JDK 7 Java 9.

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.

like image 31
Michael Easter Avatar answered Nov 08 '22 16:11

Michael Easter