OSGi provides the benefit of modularity, dependency management, service dynamism, and others. Java EE provides persistence, security, transaction management and other similar services. The Enterprise Expert Group in OSGi Alliance defines how to mix and match the Java EE APIs in OSGi. The Release 4 Version 4.2 of Enterprise Specification defines how several Java EE specifications such as JPA, JNDI, JMX, and WAR file specification can work with OSGi and levarage its benefits.
Sahoo & Siva gave a talk at JavaOne 2010 explaining the approach and advantages of writing such applications, their slides are available below:
This 6-part screencast shows how to develop OSGi-enabled Java EE applications using NetBeans and deploy them on GlassFish. The screencast creates a simple OSGi service which is invoked by OSGi client. The same OSGi service is then invoked by Web Application Bundle (WAB) client that is a Web Application + OSGi bundle, a.k.a hybrid application. The OSGi service is then replaced by an EJB-based service using Java Persistence API. This shows how OSGi client and service can seamlessly interoperate with Java EE counterparts.
Specifically, the different parts show:
1. How to create a parent POM project
2. API and Service OSGi Bundle
3. Client OSGi Bundle invoking an OSGi Service
4. Web Application Bundle (WAB) client invoking an OSGi service
5. Client OSGi bundle invoking EJB service
6. Conclusion and other possible extensions
This entire exercise was scheduled as S313522 hands-on lab at JavaOne 2010 but could not be conducted because of technical difficulties. We hope you are able to follow the steps mentioned below and benefit from it.
Please download and install NetBeans 6.9.1 and download the following zip files before attempting the exercise:
- GlassFish 3.1 b20 Web Profile
- GlassFish OSGi Feature Pack for 3.1 b20
- S313522 Detailed Docs + Solutions
If you are using a different build of GlassFish then the OSGi Feature Pack can be downloaded by executing the following script in "glassfish/modules/autostart" directory and giving the build number as the first parameter:
curl -C - -O http://download.java.net/maven/glassfish/org/glassfish/osgi-http/3.1-b$1/osgi-http-3.1-
b$1.jar
curl -C - -O http://download.java.net/maven/glassfish/org/glassfish/osgi-platforms/felix-webconsole-
extension/3.1-b$1/felix-webconsole-extension-3.1-b$1.jar
curl -C - -O http://download.java.net/maven/glassfish/org/glassfish/osgi-jpa/3.1-b$1/osgi-jpa-3.1-b$
1.jar
curl -C - -O http://download.java.net/maven/glassfish/org/glassfish/osgi-ejb-container/3.1-b$1/osgi-
ejb-container-3.1-b$1.jar
curl -C - -O http://download.java.net/maven/glassfish/org/glassfish/admingui/glassfish-osgi-console-
plugin/3.1-b$1/glassfish-osgi-console-plugin-3.1-b$1.jar
curl -C - -O http://www.reverse.net/pub/apache/felix/org.apache.felix.webconsole-3.1.2.jar
A typical execution of this script might look like:
./gf-osgi-fp.sh 20
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 27522 100 27522 0 0 74967 0 --:--:-- --:--:-- --:--:-- 120k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6795 100 6795 0 0 17811 0 --:--:-- --:--:-- --:--:-- 24068
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 24342 100 24342 0 0 59168 0 --:--:-- --:--:-- --:--:-- 108k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16145 100 16145 0 0 72180 0 --:--:-- --:--:-- --:--:-- 186k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 18724 100 18724 0 0 35921 0 --:--:-- --:--:-- --:--:-- 48785
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 602k 100 602k 0 0 636k 0 --:--:-- --:--:-- --:--:-- 748k
Enjoy the video!
How are you using OSGi and Java EE together ? What other OSGi features would you like to see in GlassFish ?
Technorati: screencast javaone osgi javaee netbeans glassfish
Related posts:- Screencast #38: “Developing OSGi-enabled Java EE Applications using GlassFish” Tutorial at EclipseCon 2011
- S313522: Instructions for OSGi-enabled Java EE Applications Hands-on Lab at JavaOne 2010
- Oracle at Eclipse Con 2011: OSGi-enabled Java EE Applications using GlassFish Tutorial and Other Sessions
- Eclipse Con 2011 Tutorial #1987 Software Prereqs: Developing OSGi-enabled Java EE Applications using GlassFish
- TOTD #130: Invoking a OSGi service from a JAX-WS Endpoint – OSGi and Enterprise Java
this is great, i was looking around for something like this. Would really appreciate if you could create simple netbeans projects that could be downloaded for each of the concepts that you have in your TOTD.
thanks a lot …. keep up the good work.
Comment by ranjan — October 4, 2010 @ 9:01 pm
ranjan,
I’ve started including them recently and will try to be more regular about them
Comment by Arun Gupta — October 5, 2010 @ 7:10 am
Two extension are directly available as "Add-on" in the "Update Tool" utility:
- "GlassFish OSGi Admin Console" which install: glassfish-osgi-console-plugin.jar ; felix-webconsole-extension.jar and org.apache.felix.webconsole.jar
- "GlassFish OSGi HTTP Service" which install: osgi-http.jar
In fact you just have to select "GlassFish OSGi Admin Console" since osgi-http is a dependency.
It would be nice to have osgi-jpa and osgi-ejb-container in the add-on as well.
Comment by Bruno — October 5, 2010 @ 8:21 am
I just noted a few point as I did the demo:
- there is a pom.xml at the root that is a copy of the solution pom. Maybe it is on purpose for the user to jump start its dev ?
- A little update: The POM uses a beta version for
org.apache.maven.plugins.maven-war-plugin.
But the final version has been released, so you can simplify: use 2.1instead of 2.1-beta-1.
- I also uses source and target 1.6 instead of just 1.5.
- I created a new domain with "developer" profile (to have a clean start). I set up no password, but the OSGi console asked me for a password. I guess that I used to set admin/admin when I first installed an old 3.1 build.
- Using Chrome, the pages didn’t automatically refresh when adding the repository (note: my repo is rich …)
- The biggest problem is that I cannot see the System.out. I know it should be redirected to the server.log, but it doesn’t. And in the "GlassFish OSGi Administration Console", in the "Log Service" tab, I have "Log Service is not installed/running."
Very interesting stuff anyway !
Comment by Bruno — October 6, 2010 @ 7:32 am
I just installed the b23 updates. I can see the System.out ! (maybe there was a problem in b22)
Also I found that to have the "Glassfish OSGi Console" display OSGi related logs, I installed the bundle :
curl -C – -O http://www.reverse.net/pub/apache/felix/org.apache.felix.log-1.0.0.jar
Could you point me to some forum about Hybrid apps ?
Comment by Bruno — October 7, 2010 @ 1:37 am
Bruno,
Thanks for your detailed comments and feedback. How are you using this demo ?
Feel free to post comments to or we can continue the discussion here.
-Arun
Comment by Arun Gupta — October 7, 2010 @ 4:33 am
Bruno,
1. osgi-jpa and osgi-ejb-container are now part of default glassfish distribution.
2. When you add a repo, it does not refresh automatically even on firefox. I find it annoying.
3. currently felix web console is not sharing the security credentials of appserver, so it does not matter what your glassfish domain username/password is. I have an AI to fix this sometime. BTW, now the web console is integrated with glassfish admin console and works across clusters of glassfish nodes.
4. Send your questions to .
Thanks,
Sahoo
Comment by sahoo — November 24, 2010 @ 10:53 am