Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet container - duplicate class definition

 
Tomasz Szymanski
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
do you know if I can count on any predictible behaviour of a servlet container if I have a duplicate class definition in the classpath (for example the same class packaged in two different JARs in /WEB-INF/lib)?
Is that kind of situation addressed anywhere in the servlet specification? Or perhaps in the general JVM (classloader) specification?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing the Servlet Spec regarding this. Don't do it.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. And I've seen unpredictable behavior. Well, it is predictable in that "it depends on which code is loaded first." But that's not something one can rely on.
 
Tomasz Szymanski
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I meant, Jeanne - I was wondering whether you can rely on any particular class loading order. And thus - if it's theoretically possible to "patch" a web application without replacing an old JAR, but by adding a new one, which would kind of override the old one. But from what you both said - it isn't. Thanks, both of you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct. it isn't.

You like Russian Roulette?
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Would loading the Class in Parent class loader help in such cases?
Based on the principle - "If webapp class loader needs some class it would check if Parent has one and if it is not there then it will try to load it from WEB-INF\lib or WEB-INF\classes".

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I repeat, you like Russian Roulette?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And once the class is loaded, it is even worse. You have some classes referring to one version and others pointing to another. Bear is correct. Abandon this idea!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic