As far as I've read, the dev:watch command of apache karaf should help developing osgi bundles in such way that I don't have to manually update a bundle everytime I make changes to the sourcecode of that bundle.
I tried this, with one simple bundle which only consists of a Activator class. I am using maven for development.
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public void start(BundleContext context) {
System.out.println("Starting the bundle");
}
public void stop(BundleContext context) {
System.out.println("Stopping the bundle");
}
}
I installed the bundle using the karaf command:
osgi:install mvn:my.groupId/my.artifactId
then I started the bundle using osgi:start <id of my bundle>
then I started monitoring for this bundle using dev:watch --start <id of my bundle>
Karaf tells me that it monitors my bundle.
Then I wanted to test if the bundle will be updated automatically if I make changes to the source code and rebuild my bundle.
So I changed the System.out.println()'s
of the activator class and built my rebuild my bundle using mvn clean install
.
Shouldn't the bundle updates itself now? When I take a look at the karaf console I see no changes until I update the bundle manually using osgi:update (which I want to avoid, using dev:watch) ...
What am I doing wrong here?
After some hours I found the source of error.
Even if the bundle is already a SNAPSHOT version, it is not sufficient to install the bundle using osgi:install mvn:<groupID>/<artifactID>
but you have to use the <version>
too in the bundle URL: osgi:install mvn:<groupID>/<artifactID>/<version>
,where <version>
corresponds to the version tag specified in the pom.xml. It has to be a snapshot version like "1.0-SNAPSHOT".