如何在Gradle项目中创建Karaf shell命令

如何在Gradle项目中创建Karaf shell命令,gradle,karaf,Gradle,Karaf,我正在尝试创建自己的karafshell命令,我愿意使用Gradle来实现这一点,因为整个项目都在Gradle上 到目前为止,我找到的唯一相关文档就在这里 上面写着 See [examples/karaf-command-example] to add your own shell commands. 都是用MAVEN创建的,并且绝对没有描述在那里发生了什么魔法,以及在结果包中应该出现什么,这样我就可以在Gradle中重现它 有人能告诉我们如何在Gradle项目中实现同样的目标吗? Karaf

我正在尝试创建自己的karafshell命令,我愿意使用Gradle来实现这一点,因为整个项目都在Gradle上

到目前为止,我找到的唯一相关文档就在这里 上面写着

See [examples/karaf-command-example] to add your own shell commands.
都是用MAVEN创建的,并且绝对没有描述在那里发生了什么魔法,以及在结果包中应该出现什么,这样我就可以在Gradle中重现它

有人能告诉我们如何在Gradle项目中实现同样的目标吗?

Karaf如何识别捆绑包中存在哪些命令?

随着时间的推移,我在gradle中找不到如何实现同样的功能,但我发现了一个解决方案,它提供了相同的结果—使用OSGI声明性服务

这里有更多详细信息(请查找
osgi.command.scope
):

下面是示例代码,它允许运行带有一个可选字符串参数的command
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);
    }
}
打包一些应用程序;
导入org.osgi.service.component.annotations.component;
@组成部分(
service=SomeCommand.class,
属性={“osgi.command.scope=some”,“osgi.command.function=command”}
)
公共类命令{
公共作废命令(){
System.out.println(“SomeCommand:+”);
}
公共void命令(字符串参数){
System.out.println(“SomeCommand:+param”);
}
}