我正在尝试创建自己的Karaf shell命令,并且我愿意使用Gradle进行此操作,因为整个项目都在Gradle上。
我到目前为止找到的唯一相关文档在这里http://karaf.apache.org/manual/latest/#_shell_commands它说
See [examples/karaf-command-example] to add your own shell commands.
[Examples是使用MAVEN创建的,关于在其中发生了什么魔术以及应该在结果包中出现什么,所以我可以在Gradle中重现它,绝对没有任何描述。
有人可以告诉我如何在Gradle项目中实现相同目标吗?Karaf如何识别Bundle中存在哪些命令?
随着时间的流逝,我没有发现如何使the same成为现实,但是我遇到了提供相同结果的解决方案-使用OSGI声明式服务。
此处有更多详细信息(查找osgi.command.scope
):http://blog.vogella.com/2016/09/26/configuring-osgi-declarative-services/
这里是示例代码,它允许运行带有一个可选字符串参数的命令some:command
。
package some.application;
import org.osgi.service.component.annotations.Component;
@Component(
service=SomeCommand.class,
property = {"osgi.command.scope=some", "osgi.command.function=command"}
)
public class SomeCommand {
public void command() {
System.out.println("SomeCommand: " + "<no args>");
}
public void command(String param) {
System.out.println("SomeCommand: " + param);
}
}