Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classes or Jar, who wins?

Is it right, that in case of duplicate classes, the one in "classes" will be taken?

Consider in a web application the class A will be available directly in

WEB-INF/classes

and a part of a jar in

WEB-INF/lib

Will the one in classes always win?

like image 870
stefan bachert Avatar asked Nov 03 '22 03:11

stefan bachert


1 Answers

This depends on the class path - the classpath entry that comes first will initially win. Also, if there are multiple class loaders, a class loader that has loaded the the dependent class will be tried first. It should not depend on if classes are in the jar or not. Documented here.

In general, do not do this as having multiple classes under same name is a true recipe for disaster.

like image 105
Audrius Meškauskas Avatar answered Nov 09 '22 06:11

Audrius Meškauskas