开发者

How to create Two java webapps and mutualize jar dependencies& others files?

We have currently a web application for webservices (named ws-project). It uses 2 others projects :

  • dao-project (hibernate)
  • core-project (pojo)

ws-project (war)  
 |   
 +--dao-project (jar)   
 +--core-project (jar)   

We are using maven & spring frameworks. (& eclipse)

We would like to have a second web project displaying web pages using spring-mvc (& jsp)

web-project (war)   
 |  
 +--dao-project (jar)  
 +--core-project (jar)  

The problem is that we will have 2 web-apps. And after the deploying, each webapp will contains in /lib the 2 jars (dao-project.jar & core-project.jar). Each of them will have their own datasource & spring container invoked.

So we are thinking to do like usually, just one webapp mixing webservices & webpages.

Any s开发者_StackOverflow中文版olution to have a clean separation without those drawbacks?

Thanks in advance for your help, i appreciate, really.


Unfortunately J2EE does not specify deployment option (other then aggregating multiple wars into an EAR) you describing, leaving this to application servers. However most application servers provide some kind of mechanisms for sharing common libraries. For example, on Tomcat you would have to copy these libraries into something like $CATALINA_BASE/shared/lib but then they will be visible to all applications.


This sounds like a problem, but it can be a blessing in disguise.

Sooner or later you will have to fix bugs in one web app, and some of those bugs might require the upgrading of the JAR library. If you use the same JAR library, then you will be forced to upgrade the non-broken web app and deploy both at the same time. Such inter-dependencies eventually make deployment very difficult (if not impossible) so you might reconsider binding both web apps to the same JAR file.

If you still want to bind both web apps the same JAR files, in TOMCAT you would put the jar files in the TOMCAT /lib directory (not the webapp /lib directory) which would make it available to all web apps (even ones that don't use the library). I believe the location for Tomcat is $CATALINA_HOME/common/lib. Take a look at the Tomcat class loader documentation, paying attention to the "common" sections.

I know it seems wasteful to not reuse libraries, but reusing them can create a lot of issues. For example, are you certain that the library is written to be used by multiple applications simultaneously? Some libraries that rely on disk stored configuration files or certain types of Singleton patterns might leak information between web applications. Remember, in a web application you don't typically have multiple JVMs running, all web applications are running under the same JVM.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜