You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Tobias Schoessler <to...@gmail.com> on 2010/03/15 14:45:26 UTC

Sharing DataObject Jar among web contexts

Hi,

I have many web apps sharing the same cayenne/mapping objects. I want to
share my cayenne classes among these web apps.  I have packaged the classes
successfully in a jar together with the cayenne.xml using a jndi data source
and the Map xml file. I have put this jar in the shared lib level of tomcat.


Now every web app deployed can use the mapping files without any cayenne
reference in its local WEB-INF lib. Super!

I can obviously  even use

DataContext dataContext = ServletUtil.getSessionContext(session);

to bind the DataContext to the session.

I am a bit worried now - is it really this easy?

I have not configured a org.objectstyle.cayenne.conf.WebApplicationListener
in the web apps web.xml.

Is it only used for finding the cayenne.xml in the Web-INF scope? I have
packaged the cayenne.xml with the jar in the global scope of tomcat I
therefore would not need this discovery feature.

Or is this listener used to clean up the DataContexts attached to the web
apps session? Do I need this Listener? Will the DataContexts attached lto
the session via ServletUtil leak if I do not have the WebApplication
listener defined?

Is this setup save?

thanks a lot.

Tobias

Re: Sharing DataObject Jar among web contexts

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Tobias,

This is just generally a bad practice to package "business" libraries  
in the container, and .war files should ideally be self-contained  
(aside from dependency on a subset of JEE APIs). So the best way of  
sharing is actually including your jar in a war. For controlled  
installations I guess you may bend the rules if you are comfortable  
with consequences. So if that works for you and you do not distribute  
your wars to the outside world this setup may be ok.

At the practical level there may be some nasty class loading issues,  
but it looks like you have avoided them by deploying Cayenne and your  
data objects at the same container level.

Regarding the listener... I think of it as an example of how you might  
setup Cayenne in a web app environment. There is a vast space of JEE  
configuration possibilities, so it can't fit them all. So if you don't  
need it, don't use it. I personally don't, as my context scoping is  
done via an IoC container.

Andrus


On Mar 15, 2010, at 3:45 PM, Tobias Schoessler wrote:

> Hi,
>
> I have many web apps sharing the same cayenne/mapping objects. I  
> want to
> share my cayenne classes among these web apps.  I have packaged the  
> classes
> successfully in a jar together with the cayenne.xml using a jndi  
> data source
> and the Map xml file. I have put this jar in the shared lib level of  
> tomcat.
>
>
> Now every web app deployed can use the mapping files without any  
> cayenne
> reference in its local WEB-INF lib. Super!
>
> I can obviously  even use
>
> DataContext dataContext = ServletUtil.getSessionContext(session);
>
> to bind the DataContext to the session.
>
> I am a bit worried now - is it really this easy?
>
> I have not configured a  
> org.objectstyle.cayenne.conf.WebApplicationListener
> in the web apps web.xml.
>
> Is it only used for finding the cayenne.xml in the Web-INF scope? I  
> have
> packaged the cayenne.xml with the jar in the global scope of tomcat I
> therefore would not need this discovery feature.
>
> Or is this listener used to clean up the DataContexts attached to  
> the web
> apps session? Do I need this Listener? Will the DataContexts  
> attached lto
> the session via ServletUtil leak if I do not have the WebApplication
> listener defined?
>
> Is this setup save?
>
> thanks a lot.
>
> Tobias