Screencast #32: OSGi-enabled Java EE Applications using NetBeans and GlassFish

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:

  1. GlassFish 3.1 b20 Web Profile
  2. GlassFish OSGi Feature Pack for 3.1 b20
  3. 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$1/osgi-http-3.1-
curl -C - -O
curl -C - -O$1/osgi-jpa-3.1-b$
curl -C - -O$1/osgi-
curl -C - -O
curl -C - -O

A typical execution of this script might look like:

./ 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


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.

Posted by ranjan on October 04, 2010 at 02:01 PM PDT #


I've started including them recently and will try to be more regular about them :-)

Posted by Arun Gupta on October 05, 2010 at 12:10 AM PDT #

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.

Posted by Bruno on October 05, 2010 at 01:21 AM PDT #

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
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 !

Posted by Bruno on October 06, 2010 at 12:32 AM PDT #

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

Could you point me to some forum about Hybrid apps ?

Posted by Bruno on October 06, 2010 at 06:37 PM PDT #


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.


Posted by Arun Gupta on October 06, 2010 at 09:33 PM PDT #


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


Posted by sahoo on November 24, 2010 at 02:53 AM PST #

helloo sir
how can i get the link for downloading "jmaki plugins"????

Posted by guest on January 15, 2012 at 11:37 PM PST #

jMaki plugins are no longer supported.

Posted by guest on January 24, 2012 at 09:05 AM PST #

I'm developing a portlet for Liferay 6.1 Community Edition on glassfish 3.1.2 (b19 or later) and would like to know how a portlet can access (particularly for JPA purposes) obtain container managed objects instances to work with? I wonder whether OSGi might help in this regard? in particular: how can a portlet get an EJB bean or OSGI managed object? Liferay portlets seem to have their classloader via the liferay-portal application and can not directly use the CDI mechanism directly.


EntityManagerFactory emf;

emf always comes up as being null.

I have also tried a portlet that locally instantiates a local JPA entity manager factory etc, and, after a fresh start of glassfish, that's fine, however, redeploying the portlet, every time, JPA complains that the entities are not found in the metadata for the model. web searches suggest that it's because the previous JPA classes have not been closed properly. what do you suggest?

Posted by guest on January 29, 2012 at 09:18 AM PST #

I think you need to ask this question at Liferay forums.

Posted by guest on January 30, 2012 at 12:54 PM PST #

Liferay is just one implementation of a java portlet JSR 286 compliant platform. I should think that the same issues would be applicable to all portlet platforms, and, I wonder whether OSGi would be a great technology to assist. that's why I'm asking here.

Posted by pbelbin on January 30, 2012 at 04:32 PM PST #

Post a Comment:
Comments are closed for this entry.

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.

Java EE 7 Samples

Stay Connected


« March 2017