Over a million developers have joined DZone.

Debugging Spring OSGi with NetBeans IDE

· Java Zone

Learn more about how the Java language, tools and frameworks have been the foundation of countless enterprise systems, brought to you in partnership with Salesforce.

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:

Discover how the Force.com Web Services Connector (WSC) is a code-generation tool and runtime library for use with Force.com Web services, brought to you in partnership with Salesforce.


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}