简体   繁体   English

管理Java J2EE Web容器中部署的多个Web应用程序的策略

[英]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: 我在tomcat Web容器中部署了多次战争(5次以上),如下所示:

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 web applications. 如您所见,Web应用程序使用的库存在重叠。 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. 我担心在第一种方案下我的容器的内存要求不是最理想的,因为log4j.jar和spring.jar加载了两次,即使它们的版本完全相同。 I don't really know how web containers work - perhaps the web container (Tomcat) is intelligent enough not to load the libraries twice. 我真的不知道Web容器的工作原理-也许Web容器(Tomcat)足够智能,不会两次加载库。

Refer to https://sec1.woopra.com/docs/class-loader-howto.html for a link on how tomcat classloaders work. 请参阅https://sec1.woopra.com/docs/class-loader-howto.html ,以获取有关tomcat类加载器如何工作的链接。

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. 在您当前的结构中,这些类将由特定于每个Web应用程序的单独的类加载器加载,并且如果您对此感到担忧,则可以修改布局以将公共类单独放置。 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. 如果要将一个应用程序从Spring 2.5升级到3.0,而不是其他应用程序,则不能共享jar。

Unless you are actually seeing problems with multiple applications suffering because of including individual jars with each app, I wouldn't change it. 除非您实际看到由于每个应用程序都包含单独的jar,导致多个应用程序出现问题,否则我不会更改它。

If you are concerned about the memory, put your libs into $CATALINA_BASE/lib, this is the commond server classpath. 如果您担心内存,请将您的库放入$ CATALINA_BASE / lib,这是公用服务器的类路径。 If you apps are semantically similiar, I'd merge. 如果您的应用在语义上相似,我会合并。 Otherwise I'd never put a webapp lib into the server's classpath. 否则,我绝不会将webapp库放入服务器的类路径中。 This is a clear violation if separation of concerns. 如果关注点分离,这显然是违反行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM