ExtremistEnigma
ExtremistEnigma

Reputation: 241

How does Java know which class to use during runtime given jars containing same classes but different JRE versions in the classpath?

My project includes two jars (xyz-jre7.jar and xyz-jre8.jar) in the classpath, which contain classes with identical names. During runtime, my program seems to pick up the correct jar and classes with both JRE 7 and 8. Internally, how does Java know which class to use? In which file(s) are these checks made?

Upvotes: 4

Views: 315

Answers (1)

Gonzalo Matheu
Gonzalo Matheu

Reputation: 10064

The default ClassLoader load classes from jar files in non deterministic order. If there are two or more classes with same fully qualified name, the first one loaded wins.

Application server usually have custom ClassLoaders

Upvotes: 1

Related Questions