【发布时间】:2016-09-09 02:26:20
【问题描述】:
我正在尝试使用 bndtools 来创建我的 OSGI 程序。这是我之前的代码,它可以很好地与 felix 控制台配合使用。
package com.buaa.ate.service.data.command;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.apache.felix.service.command.CommandProcessor;
import com.buaa.ate.service.api.data.Publisher;
@Component(
service=PublishCommand.class,
property={
CommandProcessor.COMMAND_SCOPE + ":String=example",
CommandProcessor.COMMAND_FUNCTION + ":String=publish",
}
)
public class PublishCommand {
private Publisher publishSvc;
@Reference
public void setPublisher(Publisher publishSvc) {
this.publishSvc = publishSvc;
}
public void publish(String content) {
publishSvc.start();
long result = publishSvc.publish(content);
System.out.println(result);
publishSvc.stop();
}
}
现在,我想像这样更改注释:
package com.buaa.ate.service.data.command;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.apache.felix.service.command.CommandProcessor;
import com.buaa.ate.service.api.data.Publisher;
@Component(
service=PublishCommand.class,
properties="com/buaa/ate/service/data/command/config.properties"
)
public class PublishCommand {
private Publisher publishSvc;
@Reference
public void setPublisher(Publisher publishSvc) {
this.publishSvc = publishSvc;
}
public void publish(String content) {
publishSvc.start();
long result = publishSvc.publish(content);
System.out.println(result);
publishSvc.stop();
}
}
这是我的属性文件: config.properties
内容是这样的:
osgi.command.scope\:String:example
osgi.command.function\:String:publish
当我运行程序时,输入命令'publish something',然后问题就出现了:
'gogo: CommandNotFoundException: Command not found: publish'
那么,我应该怎么做才能解决这个问题呢?
【问题讨论】:
标签: java properties annotations osgi declarative-services