aspose file tools*
The moose likes Tomcat and the fly likes Communication betwwen 2 war files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Communication betwwen 2 war files" Watch "Communication betwwen 2 war files" New topic
Author

Communication betwwen 2 war files

Nishita Jain
Ranch Hand

Joined: Mar 30, 2006
Posts: 97
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


Nishita
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Nishita Jain
Ranch Hand

Joined: Mar 30, 2006
Posts: 97
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

Joined: Mar 22, 2000
Posts: 12823
    
    5
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Mar 30, 2006
Posts: 97
Thank you very much to all for this information.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Communication betwwen 2 war files