This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Scopes in WARs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Scopes in WARs" Watch "Scopes in WARs" New topic

Scopes in WARs

Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
Is it ok to have different versions of the same class in different WARs?
If I implement a singleton object, will they be the same object when called from different WARS?
Junaid Bhatra
Ranch Hand

Joined: Jun 27, 2000
Posts: 213
Generally different .wars are loaded by separate classloaders. Hence there will be multiple (and incompatible) copies of any common classes present in those wars. For eg, a singleton won't really be a singleton, and each war will load it's own copy of the class.
If you truly want, say a singleton, it should be present up the classloader hierarchy. This can be achieved by placing it in the classpath. This is generally how containers load classes, although there's no guarantee.
jQuery in Action, 2nd edition
subject: Scopes in WARs
Similar Threads
WA #1.....word association
Two war files in a single ear file and each war files has a static variable
Shared Security Contexts?
Session Info/Timeout
Shared Security Contexts?