Discussions

Web tier: servlets, JSP, Web frameworks: How to share common jars between 2 web applications?

  1. Dear all, I want to ask your advice for the following problem: I have a lot of web applications which are using common jars like Hibernate and Spring jars. I don't want to put all these jars in each web application, but I want to have all the common jars only in one place for all the applications. I am using currently Tomcat as a web container and I can put the jars under shared/lib directory, but this solution doesn't work for me because different web apps may use different version of the same framework and if I put all of them in the shared lib there will be class loading conflicts. Would it be a good idea if I make OSGI modules for the web apps? If that's a good idea, could give me some link/example where I can read more about that? Thank you for any comment! Kind regards, Chavdar
  2. First of all if it is just the matter of third party Libraries than i guess you should the latest version of jar files in all of your webapps. i don't find any reason to use multiple versions of third-party libraries like Spring/ hibernate, though these libraries will always have backward compatibility. OSGi is not for packaging the web-applications. It allows you to build dynamically extensible applications. You can define a framework comprising of multiple OSGi bundles (components/ services) and those components would be stateless and having their life cycle methods. There are multiple Open-Source OSGi frameworks available in the market like Equinox, Spring-DM etc. Look at any of them of get more insight as to how does it work. To know about the OSGi specifications visit http://www.osgi.org/Main/HomePage
  3. Putting the jars in a common place is not possible if you are using different versions. Java's dependency specification through the manifest does not understand the notion of versions. OSGi solves this problem by using bundles which are versionable. IMHO: Its not a good idea to bring in OSGi to your environment just to solve this problem. You will only be complicating things . Packaging each app with its own dependencies into a single ear/war is better as it gives you portability as well.