问题
I want to be able to easily debug an OSGi bundle running in Apache Karaf from Eclipse. The easiest way I've identified so far is to create a Java Application launcher that starts Karaf. If the bundle was previously installed then I can set breakpoints, even in the activator, and all is good.
The issue is that when a change is made to the code, mvn install invoked, and then the Eclipse Karaf launcher invoked, I am running the old cached version of the bundle. I have played with running Karaf from the command line, installing my bundle with a Maven URL, and using dev:watch with success. But I have found that the dev:watch URLs are not persisted. Thus, when starting Karaf from Eclipse, there are no watched URLs (the previous ones were lost when Karaf was shutdown) and new versions of the bundle are not installed.
Is there a way to get the dev:watch URLs to be persistent? I looked for either properties that might hold the URLs or even Karaf command line options that could be used to specify the URLs with no luck. I even tried to add the dev:watch command to etc/shell.init.script but I get this message at Karaf startup “Error in initialization script: Command not found: dev:watch.” I assume this means the command was run too early in the Karaf startup sequence (dev feature not yet started?).
Any help would be appreciated, even alternate ways I haven’t considered to easily debug bundles running in Karaf from Eclipse. The goal is to avoid needing to use manual commands such as osgi:install every time the code changes.
回答1:
The Karaf team is now also working on a better integration with EIK, but at the current time it's not yet as deeply integrated as it would be needed. Therefore your provided way is basically the best way in doing debugging. Build your application with maven, do a dev:watch when your karaf is up and running. Since dev:watch is a "Development-Time" command it's not intended to be persistent. But you still have the history to choose from and of course you're able to provide multiple bundle IDs to the command.
来源:https://stackoverflow.com/questions/12676646/debug-karaf-bundles-in-eclipse-persist-devwatch-urls-ids