Posts Tagged ‘Equinox’

OSGi debugging

November 28, 2008 Leave a comment

OSGi debugging can turn out to be a nightmare at times, especially when using OSGi declarative services. The steps below might provide some solace.

1. Using diag OSGi command

The OSGi console is automatically enabled if you launch your bundle from eclipse launch configuration as a “OSGi Framework”. Else you could add the argument -console to your launch configuration. This will enable the OSGi console upon run.

There are lot of OSGi commands that can be used from the console. You could get the list by simply typing help at the console.

To diagnose a particular bundle, type ss at the console to see its status. This would give you a list like, for example:

osgi> ss

Framework is launched.

id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.0.v20080605-1900
1 ACTIVE org.eclipse.osgi.services_3.1.200.v20071203
2 ACTIVE org.eclipse.equinox.ds_1.0.0.v20080427-0830
4 ACTIVE org.his.bundle_1.0.0
5 ACTIVE org.her.bundle_1.0.0
6 ACTIVE org.eclipse.equinox.util_1.0.0.v20080414

Use the command diag to diagnose a particular bundle.

For instance,

osgi> diag 3

initial@reference:file:plugins/ [1]
Direct constraints which are unresolved:
Missing imported package org.someones.bundle_0.0.0.

3 is the id of the bundle above

2. Using -Dequinox.ds.print=true

Using VM argument -Dequinox.ds.print=true in your Launch configuration will echo all error messages to your console.

3. Using OSGi logging service

Start the OSGI bundle org.eclipse.equinox.log. With this bundle enabled, you could use the command log in your OSGi console.

For example,

osgi> log

>Info [2] Log created; Log Size=100; Log Threshold=4 initial@reference:file:plugins/org.eclipse.equinox.log_1.1.0.v20080414.jar/
>Info [2] ServiceEvent REGISTERED {}
>Info [2] ServiceEvent REGISTERED {}
>Info [2] ServiceEvent REGISTERED {}