Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Communication betwwen 2 war files

 
Nishita Jain
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
i have 1 question ,i tried but could not find the solution...
Question is: supposed i have 2 war files which i deployed on server(server could be any 1 .i mean it may be websphere also or tomcat).is it possible to call 1 class of 1st war file to other war files' class? and if yes then how it is possible?

thanks in advance.
Nishita
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some cross context communication is possible.

Before getting into that, may I ask why you want to do this?
There may be cleaner ways of doing what you want to do.
 
Nishita Jain
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Ben Souther,

thanks for your quick response. Actually this quesstion is asked in one of my interviews that is why i m asking this.Please reply me for the same.

Nishita
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One major intent of the design of web applications in Java is to keep applications from interfering.

This is a major security consideration and also makes it possible for you to install a new application in a server with some confidence that it will not interfere with existing applications BECAUSE it can't communicate with them.

Any communication will have to be designed in on both applications.

Bill
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContext has a getServletContext(String) method which can be used to obtain a handle to other contexts.

The spec doesn't go into a lot of detail about all the issues that need to be considered when doing this so I wouldn't expect a lot of consistency betweeen container implimentations if you go this route.

The Context element (server.xml or in context fragment files) has a crossContext attribute which has to be set to true in order to do this.
See:
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html

It is also possible to place jars or class files in a shared location within the container.
{tomcat install}/shared/lib (for jar files)
{tomcat install}/shared/classes (for class files)

Or if you also want your shared classes to be available to the container itself (such as JDBC drivers)
{tomcat install}/common/lib (for jar files)
{tomcat install}/common/classes (for class files)

Starting with Servlet spec 1.3 (or maybe 1.2) the spec has really pushed the concept of complete and whole applications; over file sharing schemes.
Build tools such as ANT, make it very easy to replicate files that need to be shared while creating war files and disk space is much cheaper these days than it used to be.
Cheap enough that it's more economical to pack each war file or app directory structure with it's own copy of a shared file than to try to maintain and test the said file in a shared environment.
[ July 26, 2006: Message edited by: Ben Souther ]
 
Nishita Jain
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much to all for this information.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic