开发者

tomcat; reference one war as a library in another war

开发者 https://www.devze.com 2022-12-16 23:31 出处:网络
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 wa

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 开发者_如何学Pythoncalling another".)

What are my options here?


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)


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消