DebuggingSpringOSGi

Debugging Spring OSGi with NetBeans IDE

[[{TableOfContentsTitle=TableOfContents} | {TableOfContents title='Table of Contents'}]]


Introduction

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

Beginning Project

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


osgi>

Debug project by Attaching Debugger

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: [1]


Debug project by NetBeans' JPDA Listen

If you use NetBeans Maven plugin, you can set `jpda.listen` to `true`, and `jpda.address` will be available as the port the application's JVM will use to connect back to NetBeans debugger. The application will need to be launched from inside NetBeans Run or Debug command.

The command to launch the application will be something like:

java -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=${jpda.address},server=n -jar equinox.jar -console

This is more convenient because no separate step to Attach Debugger is needed.

Expected Result

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:

[2]

See Also


Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo