如何在 Java 中调用 karaf 控制台命令 [英] How to call karaf console command in Java
问题描述
如果我想在我的插件 (java) 中执行一个 karaf shell 命令,该怎么做?
If I want to execute a karaf shell command in my plugin (java), how to do it?
例如:opendaylight-user@root> snmp4sdn:printdb
ex: opendaylight-user@root> snmp4sdn:printdb
org.apache.felix.service.command.CommandProcessor"可以处理吗?
"org.apache.felix.service.command.CommandProcessor" can handle it ?
推荐答案
在 Karaf 3 中,您必须使用 Felix Gogo 服务,即 CommandProcessor
.
In Karaf 3, you have to use the Felix Gogo services, ie the CommandProcessor
.
从 CommandProcessor
,您可以创建一个 CommandSession
,然后在此会话上调用 execute
.
From a CommandProcessor
, you can create a CommandSession
and then call execute
on this session.
关于此的两个注意事项:
Two notes on this:
- 在 Karaf4 中,服务发生了变化 - 它不再依赖于 Gogo
- 所有的 shell 命令都使用一个底层的 osgi 服务.使用此服务总是更好,而不是创建命令和解析输出流".例如,您可以使用
BundleContext.installBundle
安装 Bundle 或通过FeaturesService
安装功能
- 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 theFeaturesService
例如,您的命令使用 org.opendaylight.snmp4sdn.ICore
服务.请参阅:打印数据库
Your command, for example, use the org.opendaylight.snmp4sdn.ICore
service. See: PrintDB
这篇关于如何在 Java 中调用 karaf 控制台命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!