此基本代码成功地使命令 scopeA:test 在 shell 中可访问:
package com.A;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.ServiceProperty;
import org.apache.felix.service.command.Descriptor;
@Component(immediate = true)
@Instantiate
@Provides(specifications = Commands.class)
public final class Commands {
@ServiceProperty(name = "osgi.command.scope", value = "scopeA")
String scope;
@ServiceProperty(name = "osgi.command.function", value = "{}")
String[] function = new String[] {
"test"
};
@Descriptor("Example")
public void test() {
System.out.println("hello");
}
}
但是,如果我添加一个依赖于另一个 OSGI 组件的构造函数,则该命令将不再可访问,并且“帮助”不会列出它。然而,捆绑包仍然可以加载到活动状态。
package com.A;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.ServiceProperty;
import org.apache.felix.service.command.Descriptor;
import com.B;
@Component(immediate = true)
@Instantiate
@Provides(specifications = Commands.class)
public final class Commands {
public Commands(@Requires B b) {
}
@ServiceProperty(name = "osgi.command.scope", value = "scopeA")
String scope;
@ServiceProperty(name = "osgi.command.function", value = "{}")
String[] function = new String[] {
"test"
};
@Descriptor("Example")
public void test() {
System.out.println("hello");
}
}
B的内容很简单:
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
@Component(immediate = true)
@Instantiate
@Provides
final class B {
}
为什么不再列出该命令的任何想法?查找有关状态的更多信息以便我可以更好地调试的提示?