Hi Mike!
I have something like that working.
I have a "base" project that has all hibernate, user management, etc.
And other projects that work like plugins. I can drop the jars from
one of those projects in the war, and automatically get the
functionality.
There are 2 important techniques that make that work:
1. I have spring importing additional applicationContext files from
the jars with :
<import resource="classpath*:META-INF/applicationContext-*.xml"/>
so I can define new beans in the "plugin" projects, and get them
working in the webapp.
2. I'm using a spring BeanFactoryPostProcessor that takes references
from beans in the plugins and "injects" them in other beans of the
base project. An example are hibernate mapping files, were on the base
i have something like:
<bean id="sessionFactory" class="...">
...
<property name="mappingResources">
<list>
<value>pt/telindus/ikon/model/Model1.hbm.xml</value>
<value>pt/telindus/ikon/model/Model2.hbm.xml</value>
</list>
</property>
</bean>
and on the plugin I have something like:
<bean class="...PluginBeanFactoryPostProcessor">
<property name="extensionBeanName" value="sessionFactory"/>
<property name="propertyName" value="mappingResources"/>
<property name="values">
<list>
<value>pt/telindus/ikon/model/Model3.hbm.xml</value>
</list>
</property>
</bean>
this takes, Model3.hbm.xml and "injects" it in the sessionFactory,
before it is initialized.
I use the second technique quite extensively as a kind of lightweight
plugin system.
regards,
João Nelas
On Dec 17, 2007 7:19 PM, Mike Wille <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
Just one war file. They are stand alone projects in the sense that
there are two maven projectsI started down this path after reading:
http://maven.apache.org/plugins/maven-war-plugin/examples/war-overlay.html
I just realized that there is no corresponding feature for JARs.
So my
Project B core project with Dependency on Project A core (a jar)
is not
being overlayed but simply made available like normal. Duh!
So now it seems I was asking to do something that wasn't possible...
-Mike
Alexander Coles wrote:
> I am not quite clear - if that's the case, then project A and
project
> B aren't standalone projects.
> In other words, how many WAR files will you be deploying to
Tomcat (or
> your container)?
>
> Cheers,
>
> Alex
>
> On 17 Dec 2007, at 19:18, Mike Wille wrote:
>
>> I just realized that I have left something out. My end goal was to
>> generate one combined web app from project A and B using the
jar/war
>> overlay feature. Does that change anything?
>>
>> Thanks!
>>
>> -Mike
>>
>> Alexander Coles wrote:
>>> I think so. I am offering this as a purely suggestion - the
system I
>>> am currently working on -- with two WARs/web apps - is constrained
>>> by exactly what you mentioned: Tomcat is the deployment
environment
>>> for the enterprise, so I don't have t he full J2EE stack
available to
>>> me.
>>>
>>> Instead I've just developed two monolithic applications, that
share
>>> JAR'ed-up code in the core module. But there's no sharing of a
>>> applicationContext at run app. Ostensibly they're entirely
separate
>>> with separate SessionFactories, etc.
>>>
>>> Let us know how it works out!
>>>
>>> Alex
>>>
>>>
>>> On 17 Dec 2007, at 18:49, Mike Wille wrote:
>>>
>>>> Yes, project A is also a stand alone project. It has both
Core and
>>>> Web modules.
>>>>
>>>> Thanks for the links. I will take a look. At first glance, it
>>>> seems that this creates an EAR file and would then require
>>>> something more then Jetty or Tomcat.
>>>>
>>>> Thanks!
>>>>
>>>> -Mike
>>>>
>>>> Alexander Coles wrote:
>>>>> Is Project A also a stand alone project, or does it just provide
>>>>> infrastructure support?
>>>>>
>>>>> If I am understanding your requirement rightly, you could
create a
>>>>> shared parent application context:
>>>>>
http://blog.interface21.com/main/2007/06/11/using-a-shared-parent-application-context-in-a-multi-war-spring-application/
>>>>>
>>>>>
http://springtips.blogspot.com/2007/06/using-shared-parent-application-context.html
>>>>>
>>>>>
>>>>> Alex
>>>>>
>>>>> On 17 Dec 2007, at 18:16, Mike Wille wrote:
>>>>>
>>>>>> Hi All,
>>>>>>
>>>>>> I'm looking for advice on setting up multiple projects. I've
>>>>>> been using the Spring MVC Modular archetype with appfuse
and it
>>>>>> works great.
>>>>>>
>>>>>> Now I was thinking about trying it out on a larger scale. I'm
>>>>>> setting up a second project (multi module) that depends on the
>>>>>> first. Everything worked out great until I went to add new
model
>>>>>> objects to my second project. I can't get the new DAOs and
model
>>>>>> to work in the Core module of the second project. I am using
>>>>>> Hibernate and I'm getting any one of a number of errors
>>>>>> (depending on how I adjust the spring config). So I'm looking
>>>>>> for the recommended way to set something like this up.
>>>>>>
>>>>>> Let me describe what I have done and the errors I am receiving.
>>>>>> I have two projects: Project A and Project B. Project A
provides
>>>>>> infrastructure support. Project B provides application
specific
>>>>>> features. Project B depends on Project A.
>>>>>>
>>>>>> 1. It appears that I cannot leverage the hibernate session
>>>>>> factory or data source from Project A. When I do not
specify a
>>>>>> SessionFactory in Project B, my DAOs fail to be created in the
>>>>>> spring context with a failed dependency on bean named
>>>>>> sessionFactory. I guess this isn't a problem really, just
>>>>>> something I needed to be aware of.
>>>>>>
>>>>>> 2. After adding a session factory and data source to Project B,
>>>>>> my annotated hibernate entities created in Project B are not
>>>>>> found. By not found, I mean my unit tests fail when attempting
>>>>>> to call DAO methods. The exeception is:
>>>>>>
>>>>>> org.hibernate.MappingException : Unknown entity:
>>>>>> company.app.model.Entity
>>>>>>
>>>>>> My hibernate.cfg.xml file in Project B (both main and test
>>>>>> directories) *does* list the entity and I even added it to
>>>>>> persistence.xml just for the heck of it. So it appears to me
>>>>>> that the Project B SessionFactory is loading the
>>>>>> hibernate.cfg.xml from Project A. I assume this because of
the
>>>>>> property: configLocation that is set to
>>>>>> "classpath:hibernate.cfg.xml". I tried changing that
setting to
>>>>>> just "hibernate.cfg.xml " in the interests of just getting the
>>>>>> tests to work. No luck there. I then went back to project
A and
>>>>>> tried renaming hibernate.cfg.xml to something like
>>>>>> projecta-hibernate.cfg.xml and then updated the SessionFactory
>>>>>> for Project A to point to that. When I do that, I get an
>>>>>> exception on build: "No hibernate.cfg.xml configuration
>>>>>> provided. Annotated classes/packages is only configurable via
>>>>>> hibernate.cfg.xml"
>>>>>>
>>>>>> I thought that maybe I could suppress Project A's
>>>>>> hibernate.cfg.xml and so I added Project A's entities to
Project
>>>>>> B's hibernate.cfg.xml, but in the end I couldn't figure out
a way
>>>>>> to suppress Project A.
>>>>>>
>>>>>> While I knew it wouldn't work, I even tried adding Project B's
>>>>>> entity declarations to Project A's hibernate.cfg.xml to try
and
>>>>>> get Project B to work. That caused Project A's build to
fail, of
>>>>>> course.
>>>>>>
>>>>>> I've tried adding an entry to Project B's spring context for a
>>>>>> HibernateExtensionPostProcessor that includes Project B's
>>>>>> entities. But that gives me a different exception:
>>>>>>
>>>>>> org.springframework.beans.factory.BeanCreationException: Error
>>>>>> creating bean with name 'sessionFactory' defined in class path
>>>>>> resource [applicationContext-dao.xml ]: Invocation of init
method
>>>>>> failed; nested exception is org.hibernate.HibernateException:
>>>>>> cannot simultaneously fetch multiple bags
>>>>>>
>>>>>> So now I'm completely lost. Is there anybody out there
that can
>>>>>> offer any help or advice? Has anyone tried to do what I am
doing?
>>>>>>
>>>>>> Thanks a bajillion for any help!
>>>>>>
>>>>>> -Mike
>>>>>>
>>>>>>
---------------------------------------------------------------------
>>>>>>
>>>>>> To unsubscribe, e-mail:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
>>>>>> For additional commands, e-mail:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
>>>>>>
>>>>>
>>>>>
---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
>>>>> For additional commands, e-mail:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
>>>>>
>>>>
>>>>
---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
>>>> For additional commands, e-mail:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
>>>>
>>>
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
>>> For additional commands, e-mail:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
>>>
>>
>>
---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
>> For additional commands, e-mail:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
>>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>