我正在尝试创建自己的 Karaf shell 命令,并且我愿意使用 Gradle 来执行此操作,因为整个项目都在 Gradle 上。
到目前为止,我找到的唯一相关文档是 http://karaf.apache.org/manual/latest/#_shell_commands ,它说
See [examples/karaf-command-example] to add your own shell commands.
Run Code Online (Sandbox Code Playgroud)
示例是使用 MAVEN 创建的,并且绝对没有描述那里发生了什么魔法以及结果包中应该出现什么,以便我可以在 Gradle 中重现它。
有人可以告诉如何在 Gradle 项目中实现相同的目标吗?
Karaf 如何识别 Bundle 中存在哪些命令?
随着时间的推移,我没有找到如何在 gradle 中做同样的事情,但我遇到了给出相同结果的解决方案 - 使用 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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
141 次 |
| 最近记录: |