aspose file tools
The moose likes EJB and other Java EE Technologies and the fly likes Two war files in a single ear file and each war files has a static variable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply Bookmark "Two war files in a single ear file and each war files has a static variable" Watch "Two war files in a single ear file and each war files has a static variable" New topic
Author

Two war files in a single ear file and each war files has a static variable

Suresh Panneer Selvam
Greenhorn

Joined: Mar 27, 2008
Posts: 9
Two war files in a single ear file and each war files has a same static variable. ear is running in single JVM. what is static variable behavior? Will it create separate install for each war or will there single static instance and will share both war files?

Thanks
Suresh Panneerselvam


SCJP, SCWCD, SCBCD, SCEA 5, ITIL V3
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26144
    
  66

Suresh,
How do they have the same static varaible? Is it in the same class? If so, it can't be in both wars. It can be in a jar used by both wars.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Pierre-Hugues Charbonneau
Greenhorn

Joined: Feb 05, 2011
Posts: 9
Hi Suresh,

Jeanne is correct.

In summary:

* Default behaviour for application server *

For 1 EAR file with 2 WAR files within same VM, the class loader tree looks like this:

1. System class loader (JDK and application server libraries)
2. Parent class loader (EAR file)
2.1 Child class loader 1 (WAR file #1)
2.2 Child class loader 2 (WAR file #2)

- Static variable defined within code at system class path is visible for everyone
- Static variable defined within EAR file itself e.g. via jar file is visible by both EAR code and both WAR file #1 & #2
- Static variable defined within WAR file itself is only visible to WAR file scope

** Note that each application server provides tuning to override the default behaviour ex: WAR file can override / preferred any class found within parent class loader **

Regards,


Regards,
P-H
http://javaeesupportpatterns.blogspot.com/
Suresh Panneer Selvam
Greenhorn

Joined: Mar 27, 2008
Posts: 9
Thanks Jeanne & Charbonneau for detailed explanation.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: Two war files in a single ear file and each war files has a static variable
 
Similar Threads
Problem in invoking ejb from different .ear
Loading multiple log4j.xml files
Ant build.xml for building ear from wars
Best packaging and deployment strategy for web applications
Multiple war in an ear file