Reputation: 5435
In Java, I recently faced a case where I was getting two different jars that each defined a class. The problem was that one of these jars was out of date and the class in question was missing a method that existed in one jar and not the other.
So, I was getting an error that the method being used in the code couldn't be found. I was eventually able to resolve this by removing the old jar, so that it imported the correct one.
Many people used this same code (with the same two, conflicting, imported jars) and did not have this problem. So, they must have been importing the up-to-date jar.
My question is this: What caused me to import one jar over another? What logic determines which is "used"?
Thanks!
Upvotes: 4
Views: 5206
Reputation: 533570
The class path determines the order in the same way that you PATH determines which program you will run if you have multiple programs witht he same name.
You can get weird bugs, but most of the time having multiple versions of a jar is not a problem (meaning it could have been there for a while and is difficult to test)
Upvotes: 2
Reputation: 23935
Look at your CLASSPATH
. What order do your jar files appear in on the CLASSPATH
?
If you're not explicitly setting the CLASSPATH
variable (or command-line arguments or however your framework finds classes), then set it in such a way that the classes you want appear earlier.
Upvotes: 1
Reputation: 14943
Based on the order. The first one will be used and the second one will start causing issues.
Make sure you don't include different versions of the same class. You may encounter weird bugs because of that.
Upvotes: 6