How to debug bundle during development has always been a problem. Today, let's look at how eclipse solves this problem.
I usedEclipse javaee indigo 3.7.2Version.
Step 1: Enable eclipse and addPlug-inProject.
Step 2: Enter the project nameHelloworldbundleNote that you must select the running mode of the plug-in here.An osgi framework.
Step 3: Enter the metadata information related to the bundle. Here we use the default value. We choose to generate automaticallyActivatorClass to simplify the subsequent processing.
Step 4: selectHello osgi bundleTemplate generation bundle project.
Step 5: Enter the startup and stop information required by the hello osgi bundle template.
Step 6: by now, eclipse automatically generates the helloworldbundle plug-in based on our selection. Although this is a very simple bundle, there is no doubt that this is a complete bundle, which can be run directly.
The directory structure of helloworldbundle:
Content of the activator. Java file:
Package Helloworldbundle; Import Org. osgi. Framework. bundleactivator; Import Org. osgi. Framework. bundlecontext; Public Class Activator Implements Bundleactivator { /* * (Non-javadoc) * @ see org. osgi. Framework. bundleactivator # Start (Org. osgi. Framework. bundlecontext) */ Public Void Start (bundlecontext context) Throws Exception {system. Out. println ( "Hello world !! " );} /* * (Non-javadoc) * @ see org. osgi. Framework. bundleactivator # Stop (Org. osgi. Framework. bundlecontext) */ Public Void Stop (bundlecontext context) Throws Exception {system. Out. println ( "Goodbye World !! " );}}
Content of manifest. MF:
Manifest-version: 1.0Bundle-manifestversion:2Bundle-Name: helloworldbundlebundle-symbolicname: helloworldbundlebundle-version:1.0.0. Qualifierbundle-Activator: helloworldbundle. activatorimport-package: org. osgi. Framework;Version = "1.3.0"Bundle-requiredexecutionenvironment: JavaSE-1.6
Step 7:Start ()AndStop ()Add two breakpoints to the method:
Step 8: Right-click the helloworldbundle project and chooseDebugSelectOsgi framework:
Step 9: Everything is OK. Eclipse switches to the debug view and the console window appears.Osgi>Prompt,CodeWe also stopped at the defined start breakpoint.
Step 10: enter at the osgi> promptCloseCommand to stop the osgi framework (shutdown and exit ). At this time, the code will stop at the Stop breakpoint.
By using the debugging function provided by ECLIPSE, we can become more powerful in the bundle development process.
More references:
Coding bundles on the slug demo movie
Remote debugging on the slug demo movie