aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Sharing of Persistence Context - Multiple WAR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Sharing of Persistence Context - Multiple WAR" Watch "Sharing of Persistence Context - Multiple WAR" New topic
Author

Sharing of Persistence Context - Multiple WAR

Juggy Obhi
Ranch Hand

Joined: Jul 02, 2007
Posts: 51
Hi All,

I need your help to know a good structure for the 3 Web Applications i am working on...

core - Web Application to serve a Mobile Phone Application (Consists mainly Servlets)
front - Front End Web Application for the Users (Struts/Spring based)
back - Back End Web Application for the Admin(Struts/Spring based)

All of these Apps uses following JARS -

commons - Project containing common Util classes, Exceptions etc - JAR
persistence - Project containing the JPA entity classes and the persistenceContext.xml under /META-INF - JAR

At present, I copy paste these two JARS in the /lib folder of my Web Apps and as a result, 3 different Persistence Contexts gets created despite it is the same, I want to share both of these jars among my Web Apps. I want a single shared Persistence Context to exist. How can i achieve this?? Please guide.


Thanks and Regards,
Jagpreet Singh

It does not matter how many times you fall,what matters is how many times you stand back.
Juggy Obhi
Ranch Hand

Joined: Jul 02, 2007
Posts: 51
Juggy Obhi wrote:
Note: I am Using TOMCAT 7 as the Server so i doubt if EAR is an option for me.

I really need help. I can see big issues with the way my apps are, alomost every thing is common with these three apps, but at this times, unwillingly i have to duplicate all my jars in all three apps along with the duplication of persistence context at three places. I see same persistence context loading 3 times when i start my tomcat server. Please guide me.
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
you have options if your 3 web applications are deployed in the same application server
a) package the 3 webapp in an ear file and put your persistence jar in the common lib folder of the ear
b) put your persistence jar the server classpath that is shared by all deployed application

Note that is option a) is a much better approach to me


SCJP 5 , SCWCD 5, SCEA 5
Juggy Obhi
Ranch Hand

Joined: Jul 02, 2007
Posts: 51
Thanks ntumba lobo!

I agree that option A is a better approach but can i deploy an EAR to Tomcat? I read somewhere that it is not possible.

I tried option B, i placed my persistence jar in Tomcat/lib but then i got ClassNotFoundExceptions.

I am still stuck
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
Sorry I didnt see you were using Tomcat. That's correct you cant use an ear file with a servlet container.
As for your ClassNotFoundException that's odd, the tomcat/lib folder should be visible to both server and webapp as far as I remember.
Can you give more details about the error if you havent solved your pb yet ?
 
jQuery in Action, 2nd edition
 
subject: Sharing of Persistence Context - Multiple WAR