Debugging Spring OSGi with NetBeans IDE
I try here to show how to create, build, and debug OSGi bundles with NetBeans IDE. For this purpose, I use Maven modules. First, I create a parent project. Next, using NetBeans 6.1, I create 4 sub-projects with the Spring DM architectype:
- exceptions : exception packages
- api : service to be implemented and published
- impl : service implementation
- test : test bundle
Full project source is available under this url : svn checkout http://debugosgi.googlecode.com/svn/trunk/ debugosgi-read-only
Now, if we launch Equinox and start or update test bundle we get jtunisie as output:
$ java -jar equinox.jar -console
log4j:WARN Please initialize the log4j system properly. osgi> ss
0 ACTIVE org.eclipse.osgi_3.3.2.R33x_v20080105 1 ACTIVE org.eclipse.equinox.common_3.3.0.v20070426 2 ACTIVE org.eclipse.update.configurator_3.2.100.v20070615 3 ACTIVE com.jtunisie.osgi.debug.debug.dao.impl_1.0.0.SNAPSHOT 4 ACTIVE org.springframework.bundle.osgi.io_1.1.0.m1 5 ACTIVE slf4j.log4j12_1.4.3 6 ACTIVE org.springframework.bundle.osgi.extender_1.1.0.m1 7 ACTIVE org.springframework.bundle.spring.core_2.5.2 8 ACTIVE org.eclipse.osgi.services_3.1.200.v20070605 9 ACTIVE org.springframework.bundle.spring.aop_2.5.2 10 ACTIVE jcl104.over.slf4j_1.4.3 11 RESOLVED com.jtunisie.osgi.debug.debug.test_1.0.0.SNAPSHOT 12 ACTIVE org.springframework.osgi.asm.osgi_2.2.3.SNAPSHOT 13 ACTIVE org.springframework.bundle.osgi.core_1.1.0.m1 14 ACTIVE slf4j.api_1.4.3 15 ACTIVE org.springframework.bundle.spring.beans_2.5.2 17 ACTIVE org.springframework.bundle.spring.context_2.5.2 18 ACTIVE org.springframework.osgi.log4j.osgi_1.2.15.SNAPSHOT 20 ACTIVE org.springframework.bundle.spring.context.support_2.5.2 21 ACTIVE org.springframework.osgi.aopalliance.osgi_1.0.0.SNAPSHOT
osgi> up 11
osgi> |
Now, to debug deployed bundle and service we put a break point on service impl and we execute this command:
| $ java -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8888,server=y,suspend=y -jar equinox.jar -console Listening for transport dt_socket at address: 8888 |
open netbeans --> Run --> attach debbuger and we change the host and port as the following picture shows:

| osgi> log4j:WARN No appenders could be found for logger (org.springframework.util.ClassUtils). log4j:WARN Please initialize the log4j system properly. Listening for transport dt_socket at address: 8888 jTunisie |
Note that NetBeans highlights the break point and we get the message on equinox console continue debug button is clicked:

- Login or register to post comments
- 1934 reads
- Email this Quick Tip
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)







Comments
Rainer P. replied on Tue, 2008/07/08 - 8:11pm
Hello,
nice to see that. But what I'm really asking myself is: Why do you make it so complicated using bleeding edge technologies? Jumping over a ditch with blindfolded eyes and handcuffed legs is complicated too. What is the benefit for business? Coding this in Java and debugging or even profiling it is a joke. So I think you are just bored?
slim.ouertani replied on Wed, 2008/07/09 - 4:35am
@Rainer
Osgi make sense with new class loading model witch is new for us. On my work, we have a project with OSGI on a server platforme.
As a newbie on OSGI, we are faced to a lot of bugs and unkown exception source. We have created a new class loader model to link inside and outside osgi container applications. One of the greatest helper is this debuger solution.
I 'm not bored, but i want to share this exeprience and get feed back and advices according to this solution.
cokke replied on Sat, 2008/07/19 - 5:21pm
hi,
when you say "Now, if we launch Equinox and start or update test bundle we get jtunisie as output:" i can't undestand.
You have equinox installed in a path outside the project or have different configuration?
I have tried to run equinox.jar from root path , but i don't undestand where and when i deploy bundles to framework after have builded with maven.
Have any dea what i do wrong ?
ty
slim.ouertani replied on Sun, 2008/07/20 - 9:14am
@cokke
You should install the bundle under any osgi container. Equinox, for instense, have the plugin directory where we can put bundles (spring dm ,...) and a configuration directory. Modify config.ini file to default install bundle from maven target project, put the bundle under plugins directory or install it by install cmd are soltution to deploy bundle.