Java OSGI bundle OSGI.command.function运行多个函数

Java OSGI bundle OSGI.command.function运行多个函数,java,osgi-bundle,Java,Osgi Bundle,我有一个OSGI捆绑包,在我的捆绑包中,我需要从命令行调用多个方法,但我还没有找到一种方法 有可能是这样的吗 osgi.command.function=myMethod1 osgi.command.function=myMethod2 然后从命令行调用其中一个方法 从现在起,我的解决方法是使用一个带参数的方法,其中一个参数决定调用哪个方法。大概是这样的: myDefaultMethod(String foo, String bar, String test){ switch (f

我有一个OSGI捆绑包,在我的捆绑包中,我需要从命令行调用多个方法,但我还没有找到一种方法

有可能是这样的吗

osgi.command.function=myMethod1

osgi.command.function=myMethod2

然后从命令行调用其中一个方法

从现在起,我的解决方法是使用一个带参数的方法,其中一个参数决定调用哪个方法。大概是这样的:

   myDefaultMethod(String foo, String bar, String test){
    switch (foo) {
            case "load":
                    myMethod1(bar)
                    break
            case:"export":
                    myMethod2(bar, test)
                    break
    }
我不喜欢这个解决方案,因为要从命令行调用myMethod1,如果我只需要2个参数,我还必须传递3个参数(foo、bar和test)


有更好的方法吗?

是的,您完全可以这样做,即使有许多相同方法的重载版本

如下:

@Component(
    service = TenantFactory.class,
    property = {
        "osgi.command.scope=myscope",
        "osgi.command.function=listTenants",
        "osgi.command.function=listTenantUsers"
    }
)
public final class TenantFactory {
    @Descriptor("List all tenants")
    public void listTenants() {
        ....
    }

    @Descriptor("List all users of given tenant")
    public void listTenantUsers(@Descriptor(TENANT_DESCR) String tenantName) {
        ....
    }
}