Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scopes in WARs

 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Thanks
Chu
 
Junaid Bhatra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic