How to call karaf console command in Java

扶醉桌前 提交于 2019-12-12 02:49:31

问题


If I want to execute a karaf shell command in my plugin (java), how to do it?

ex: opendaylight-user@root> snmp4sdn:printdb

"org.apache.felix.service.command.CommandProcessor" can handle it ?


回答1:


In Karaf 3, you have to use the Felix Gogo services, ie the CommandProcessor.

From a CommandProcessor, you can create a CommandSession and then call execute on this session.

Two notes on this:

  • In Karaf4, the service has changed - it's not dependent on Gogo anymore
  • All the shell commands use an underlying osgi service. It's always better to use this service instead of creating command and "parsing the outputstream". For example, you can install a Bundle with BundleContext.installBundle or install a feature through the FeaturesService

Your command, for example, use the org.opendaylight.snmp4sdn.ICore service. See: PrintDB



来源:https://stackoverflow.com/questions/36010963/how-to-call-karaf-console-command-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!