5

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?

stefan bachert
  • 9,413
  • 4
  • 33
  • 40
  • At least from my experience with different application servers and servlet containers I'd say "yes", but I am not sure if this is by definition or just by "common usage". Interesting question, though. – Dominik Sandjaja Feb 25 '13 at 09:27
  • Apparently so. The following link may be useful : http://stackoverflow.com/questions/4739302/web-inf-classes-vs-web-inf-lib – Chetter Hummin Feb 25 '13 at 09:27
  • as far as I know this is not specified in the standard. different application servers behave very differently. weblogic and jboss will pick the jar provided by the appserver first. – opi Feb 25 '13 at 09:37

1 Answers1

2

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.

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
  • **multiple classes under same name is a true recipe for disaster** sure, but what else could be done in a complex web app (100+ jars), when you do not control the building of jars? – stefan bachert Feb 25 '13 at 20:00