Hi. I have a web application that uses Hibernate and Spring frameworks as the infrastructure(domain objects and Spring DAOs and other stuff). This web application is packeged as a WAR file. Now, I'm trying to create a related WAR that uses the same previous Hibernate and Spring classes (but uses a different web framework, this is the main difference). AFAIK, I have to put these two WARs in one EAR file. My question is: Should I package the first WAR classes (my Hibernate and Spring classes) into the second WAR? Thanks.
either you can have two war file each having the same set of classes in the web-inf/lib as jar file. Or you can have the common classes in a jar file and copy the jar file in server lib dir. Hope this helps
I agree with Sundaram, a common jar make the most sense to me but WARs can be finicky so if you are using a build process with scripts (which everyone should be using!) you're better off copying the required files into each WAR as part of the build.
This works even if this JAR containing Hibernate & Spring related classes and files (you know, applicationContext.xml and other Hibernate hbm.xml files) ? Do you suggest to drop the EAR and use two seperated WARs? A friend of mine told me to create a JAR file and put it at the same level of the two WARs inside the EAR, then configure the class path of each WAR to include this JAR (using the MANIFEST file of META-INF dir). Of course, he assumes there is an EAR. Any ideas?
Joined: Jun 26, 2007
I had did the same with a struts application and deployed the applications as 2 WARs (although i could have packed it as one EAR). I think if you go for a WAR or EAR, if the jar file is in the web-inf/lib or server lib , which is equivalet to having it in the classpath. So i think it should work fine either ways.
Originally posted by Sundaram Karthick: either you can have two war file each having the same set of classes in the web-inf/lib as jar file. Or you can have the common classes in a jar file and copy the jar file in server lib dir. Hope this helps
This following might also work , please correct if I am wrong somewhere.
Make a ear having two wars.Do not put any jar in the /WEB-INF/lib.Put it in ear itself.Make entry in MENIFEST.MF file for each of the wars using class-path attribute , which points to all the jars in the ear.In this way your web applications would be using the same set of jars and no need to put in some application specific folder(server lib directory).