开发者

Strategies for managing multiple web applications deployed in a Java J2EE web container

I have multiple wars (5+) deployed in a tomcat web container as shown below:

war1
 +-META-INF
 +-WEB-INF
       +-classes
         +-MyClass1.class
       +-libs
         +-log4j.jar
         +-spring.jar
war2
 +-META-INF
 +-WEB-INF
       +-classes
         +-MyClass2.class
       +-libs
         +-log4j.jar
         +-spring.jar

As you can see there is an overlap in the libaries used by the we开发者_如何学JAVAb applications. Would I gain anything by combining my various applications into one monolithic application and deploying as shown below?

war3
 +-META-INF
 +-WEB-INF
       +-classes
         +-MyClass1.class
         +-MyClass2.class
       +-libs
         +-log4j.jar
         +-spring.jar

I'm concerned that the memory requirements of my container under the first scheme is suboptimal since log4j.jar and spring.jar are loaded twice even though they're exact same versions. I don't really know how web containers work - perhaps the web container (Tomcat) is intelligent enough not to load the libraries twice.


Refer to https://sec1.woopra.com/docs/class-loader-howto.html for a link on how tomcat classloaders work.

In your current structure, the classes will be loaded by separate classloaders specific to each webapp and if this concerns you, can modify your layout to put the common classes separately. But the one thing that I'd be worried about is, that this limits your individual applications flexibility. If you want to upgrade one application from Spring 2.5 to 3.0 and not the others, you can't if the jars are shared.

Unless you are actually seeing problems with multiple applications suffering because of including individual jars with each app, I wouldn't change it.


If you are concerned about the memory, put your libs into $CATALINA_BASE/lib, this is the commond server classpath. If you apps are semantically similiar, I'd merge. Otherwise I'd never put a webapp lib into the server's classpath. This is a clear violation if separation of concerns.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜