I know that there are already some issues related to this topic, but I have not yet found a real solution.
I am currently developing applications with EE6 using JPA, CDI, JSF. I would like to take a more modular approach than packing everything in a WAR or EAR and deploying it all on an application server.
I am trying to create my applications as modular as possible by dividing the module into 3 maven projects:
- API - Contains Interfaces for Services (Stand Alone)
- Model. Contains JPA objects for a specific module.
- Impl - contains an implementation of the API, mainly CDI beans
The presentation logic of each module is currently included in a large web project, which is ugly. I already thought about web fragments, but if I distributed my bean classes and xhtml files in jar files, I would have to implement a hook so that the resources could be viewed by the parent web application. Such a solution, at least, will allow me to have a fourth project for a module that will contain all the presentation logic associated with the module, which is a good start.
What I want is not only that I can have these 4 types of projects, but also each project with the possibility of "hot" replacement. This led me to OSGi, which was really cool at first, until I realized that EE6 technologies are not well supported in the OSGi container.
Jpa
First, consider a JPA. There are several tutorials [1] that explain how to create an OSGi package with JPA support enabled, but none of these guides show how to distribute entities into different packages (model module project). I would like to have, for example, three different modules
The model project of the blog module has (compilation time) a dependency on the model project of the user. The user module model project has (compilation time) a dependency on the kernel model project.
How can I get JPA to work in such a scenario without having to create a save unit for each module model project? I want one persistence unit to be aware of all the objects available at runtime. Model projects in which entities should, of course, be a hot swap. Perhaps I will need to create a separate project for each client, which imports all the necessary project objects and contains a persistence.xml file that includes all the necessary settings. Are there any maven plugins available to create such projects, or even other approaches to solve this problem?
Cdi
CDI is very nice. I really like it and I don’t want to miss it anymore! I use CDI extensions like MyFaces CODI and DeltaSpike which are awesome! I introduce my (stateless) services into other services or at a presentation level that is simply great. Since my services are stateless, it should not be a problem to use them as OSGi services, but what about integrating CDI into OSGi? I discovered a CDI Extension [2] for glass fish that would introduce OSGi Services into CDI beans, but I also want OSGi Services to be CDI beans. I'm not quite sure how to achieve this, I probably have to use BeanManager to instantiate the implementations, and then register each implementation for my interface in the ServiceRegistry in the BundleActivator. Is there a standard way to do this? I would like to avoid any dependencies (compilation time) with the OSGi base.
I would also like to use my services the way I use them right now, without changing anything (implementations are not annotated, and injection points are not qualified). There is a JBoss Weld extension / sub project [3] that seems to be targeting this problem, but it seems to be inactive, I cannot find any recommendations or instructions. How can I leave my implementation as it is, but still use OSGi? I mean, you should not add annotation to the implementations, since each implementation is already annotated with the annotation of the stereotype, in any case, I would like to prevent this.
Jsf
As mentioned earlier, I would like to be able to distribute my logical look module. As far as I know, this is really impossible out of the box. Pax Web [4] must somehow solve this, but I am not familiar with it.
I would like to have a "CoreWeb" project in the "core" module that contains the Facelet template, and name it "template.xhtml". The JSF page in the project called "BlogWeb" in the "blog" module should then be able to link to this template and apply composition.
To be able to extend the view, I would introduce the Java "Extension" interface, which can be implemented by a specific module class. The controller for presentation then introduces all implementation implementations. For example, an extension provides a list of sub-items that will be included in the main view.
The described extension mechanism can be easily implemented, but the following requirements must be met:
- When adding new OSGi suites to the application server, the set of available extensions may change; extensions must be available for the view controller.
- The mobility (from a separate package) that should be included in the main view should be available.
The concept of a single host, but several Spring Slices cut-off applications [5] is very interesting, but seems limited by Spring DM Server, and the project also seems to be inactive.
Summary
After all the examples and behaviors that I described, I hope you know what I would like to achieve. It is just an EE6 application that is very dynamic and modular.
What I'm looking for in the end is at least the documentation of how everything works, how I expect, or even a better working solution!
[1] http://jaxenter.com/tutorial-using-jpa-in-an-osgi-environment-36661.html
[2] https://blogs.oracle.com/sivakumart/entry/typesafe_injection_of_dynamic_osgi
[3] http://www.slideshare.net/TrevorReznik/weldosgi-injecting-easiness-in-osgi
[4] http://team.ops4j.org/wiki//display/paxweb/Pax+Web
[5] https://jira.springsource.org/browse/SLICE