1

If two jars with same content(say jarA , jarA_old ) are added into the class path of the working jar (i.e inside the manifest file of the main jar, which has both jarA and jarA_old in its library folder) . Then, which Jar will be considered when a class inside them is called or imported??

JarA has this in its manifest:

Build-Date: Fri, 18 May 2012 12:28:40
Build-Environment: x86 Windows XP 5.1
Build-Number: 5

JarA_old this in its manifest:

Build-Date: Wed, 23 Nov 2011 06:34:39
Build-Environment: x86 Windows XP 5.1
Build-Number: 4

exept this all other details are similar..

1ac0
  • 2,875
  • 3
  • 33
  • 47
adarsha bv
  • 43
  • 2
  • 13

3 Answers3

1

The ClassLoader will try to find the classes in all the jars of the classpath, in order. As soon as it finds it in a jar, it loads it from this jar.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
1

Oracle says:

Specification order

The order in which you specify multiple class path entries is important. The Java interpreter will look for classes in the directories in the order they appear in the class path variable. In the example above, the Java interpreter will first look for a needed class in the directory C:\java\MyClasses. Only if it doesn't find a class with the proper name in that directory will the interpreter look in the C:\java\OtherClasses directory.

Olavi Mustanoja
  • 2,045
  • 2
  • 23
  • 34
0

see Java: Which of multiple resources on classpath JVM takes?, it searches the jars in the order as they are listed. The first found match is used.

Community
  • 1
  • 1
cello
  • 5,356
  • 3
  • 23
  • 28