Ouertani Slim was born in Tunisia in 1981. Now he is a software engineer since 2004 and he is Java 6 and Spring certified with 100% and 94% respectively. He is very interested in Java technology, Scala and open source projects. He believes that programming is one of the hardest jobs and most beautiful in the world. Slim has posted 32 posts at DZone. You can read more from them at their website. View Full User Profile

Debugging Spring OSGi with NetBeans IDE

  • submit to reddit
NetBeans is my favorite IDE but it suffers from lack of OSGi support. Eclipse with Equinox and plug-ins wins in terms of fast build, test, and deploy.

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:


  1. exceptions : exception packages
  2. api : service to be implemented and published
  3. impl : service implementation
  4. 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

osgi> log4j:WARN No appenders could be found for logger (org.springframework.util.ClassUtils).
log4j:WARN Please initialize the log4j system properly.

osgi> ss

Framework is launched.

id State Bundle
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> start 11

osgi> jTunisie

osgi> up 11

osgi> jTunisie


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

Note that NetBeans highlights the break point and we get the message on equinox console continue debug button is clicked:

Your rating: None
Published at DZone with permission of its author, Slim Ouertani.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Rainer P. replied on Tue, 2008/07/08 - 7:11pm


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 - 3:35am



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.



gerardo mancini replied on Sat, 2008/07/19 - 4:21pm


 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 ?


Slim Ouertani replied on Sun, 2008/07/20 - 8:14am


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. 











Jacek Laskowski replied on Tue, 2008/09/30 - 2:12am


Don't get me wrong, but I think the title is a bit exaggerated. It caught my attention as I'm doing some osgi experiments and scratched my head what's new in this entry. The debug approach you presented is no different than doing it with any other java application, equinox or spring-dm (formerly spring-osgi) including. It should just work. However I'd consider using -agentlib:jdwp as an alternative to the older -Xdebug available for releases prior to Java 5.0.

Looking forward to reading more about OSGi from you soon.


Slim Ouertani replied on Tue, 2008/09/30 - 2:41am in response to: Jacek Laskowski



Thanks for advance.

Yes, I'am agree with you. However, the first time that I used this command line is with OSGI, else I' m based on IDE tools and debug button :).

The title is exaggerated, may be attaching debugger with netbeans will be appropriete.


Jacek Laskowski replied on Tue, 2008/09/30 - 4:06am


I think "Debugging OSGi with NetBeans IDE and JPDA" would do the trick. On the other hand, after some thinking, I must admit the title might've led me to wrong conclusions, but I can't find any better ;-)

I believe I'll be able to read more about OSGi soon from you, right? If you could post some tips&tricks on running NetBeans RCP app atop OSGi, that'd be awesome.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.