Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programatically invoke a Felix/Karaf shell command?

I want to automatically invoke the Karaf "dev:watch" command if I detect that I'm running in a dev environment. I've considered adding dev:watch * directly to etc/shell.init.script but I don't want it to run unconditionally. So, I'm considering creating a simple service that checks a Java property (something simple like -Ddevelopment=true) and invokes org.apache.karaf.shell.dev.Watch itself. I think I can ask OSGi for a Function instance with (&(osgi.command.function=watch)(osgi.command.scope=dev)) but then I need to create a mock CommandSession just to invoke it. That just seems too complicated. Is there a better approach?

like image 405
Chris Dolan Avatar asked Jul 01 '26 08:07

Chris Dolan


1 Answers

Since Apache Karaf 3.0.0 most commands are backed by OSGi services.

So for example the bundle:watch command is using the service "org.apache.karaf.bundle.core.BundleWatcher".

So just bind this service and you can call the bundle:watch functionality very conveniently.

like image 117
Christian Schneider Avatar answered Jul 05 '26 18:07

Christian Schneider