views:

267

answers:

3

I have a few tomcat applications, deployed in tomcat using .war files. Even though these wars are separate from each other, they are all part of a larger concept / application, and quite often, one war needs to call code from another war.

Let's say I have 2 .wars, "a.war" and "b.war"... I would like to be able to use some classes found in "a.war", from within "b.war". One option of course is to split the common code out into a third ".jar", but for reasons that I don't want to get into, that will cause other problems (and besides, in my case it's not so much a case of "common code", but more like "one application calling another".)

What are my options here?

A: 

If it's just "one application calling another", you can use Java RMI.

BranTheMan
+1  A: 

If the intent here is for "sub-apps" in separate .wars to communicate with each other in the grand scheme of a larger app, rather than shared code/lib, I would recommend:

  1. Servlets - set up Servlets to facilitate communication between these apps, so that they can talk to each other. Register the servlets in your web.xml files, run some connectivity tests for the expected servlet urls, and you will be up and running shortly.

  2. Webservices - find a suitable webservice implementation for your apps, and create a wsdl.

  3. RMI, like BranTheMan is suggesting.

  4. crossContext communication between Servlets (have not tried this)

kg
Maybe I'm misunderstanding how tomcat works... don't two .war applications in a tomcat "webapps" dir share the same jvm? If so, servlets, webservices, and rmi are all overkill; there has to be a better method of application integration in tomcat, then diving down to the socket level... I would hope...
If the .wars are all running in the same tomcat webapps dir, then they will be running under one tomcat jvm. I was thinking in terms of multiple tomcat deployments, one for each app, but looking at the original question, you are correct. The crossContext ability of Servlets might be useful in the case of one tomcat container:http://stackoverflow.com/questions/661978/what-does-the-crosscontext-attribute-do-in-tomcat-does-it-enable-session-sharing
kg
A: 

I'm not sure that you're against creating a .jar entirely, or just against the idea of creating 1 jar per application, but in tomcat there is the idea of shared libraries.

In Tomcat 5.5, it's in /shared/, in Tomcat 6, its just under /lib. If you put .jars (or .class files? Never tried) up there, they may be referenced by any .war in the same server instance.

On one hand, this is nice, makes the .wars nice and small, and probably helps with permgen space, but on the other hand, it is hard to version artifacts if they're shared by many .wars.

lucas