- 在
第五章
的基础上,将OSGi_equinox_consumer
项目下的META-INF/MANIFEST.MF
文件中的Bundle-Activator
项删除 - 在
MANIFEST.MF
中添加org.eclipse.osgi.framework.console
Bundle的支持
- 在
com.freud.osgi.consumer
目录下新建一个PracticeService
的类,内容为
package com.freud.osgi.consumer;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
import com.freud.osgi.HelloWorldService;
public class PracticeService implements CommandProvider {
private HelloWorldService helloWorldService;
public void _say(CommandInterpreter ci) {
ci.println(helloWorldService.sayHello(ci.nextArgument()));
}
public synchronized void unsetHelloWorldService() {
this.helloWorldService = null;
}
public synchronized void setHelloWorldService(
HelloWorldService helloWorldService) {
if (this.helloWorldService != helloWorldService) {
this.helloWorldService = helloWorldService;
}
}
@Override
public String getHelp() {
String ret = "pring the help info for <say>";
System.out.println(ret);
return ret;
}
}
- 在项目下新建一个文件夹
OSGI-INF
- 在
osgi-INF
目录右键
,新建一个Component Definition
,修改Class为om.freud.osgi.consumer.PracticeService
- 打开
component
文件,切到Services
的tab下,在Referenced Services
上Add添加一个新的Reference Service
为“HelloWorldService”
,然后点击Edit
编辑如下内容 - 在
Provided Services
中点击Add添加org.eclipse.osgi.framework.console.CommandProvider
- 上两步的
截图
如下
- 重新
运行
- 在控制台中尝试输入
say freud
- 在控制台输入
services *HelloWorldService
, 输出为这个Service的Bundle使用状态
。 - 在控制台中尝试输入
say freud
- 在控制台输入
help say
输出say的Helper info
参考资料
视频教程 : http://v.youku.com/v_show/id_XNDE1NzU0OTY0.html
Equinox OSGi官网 : http://www.eclipse.org/equinox/
林昊 : 《OSGi原理与最佳实践》
Richard S. Hall : 《OSGi实战》