OSGi bundle activator不工作解决

问题:

在OSGi编程中,编写一个bundle,但等WEB服务器启动后,发现该activator不工作,start()方法没有执行。

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

import com.sgcc.hf.test.osgi.service.HelloService;

public class HelloServiceActivator implements BundleActivator {  
    ServiceRegistration helloServiceRegistration;  
    @Override  
    public void start(BundleContext context) throws Exception {  
    	System.out.println("HELLOSERVICE BUNDLE STARTING...");
    	
        HelloService helloService = new HelloServiceImpl();  
        helloServiceRegistration = context.registerService(HelloService.class  
                .getName(), helloService, null);  
    }  
  
    @Override  
    public void stop(BundleContext context) throws Exception {  
    	System.out.println("HELLOSERVICE BUNDLE STOPPING...");
        helloServiceRegistration.unregister();  
    }  
  
}  

通过ss命令查看bundle,该bundle已经是激活状态。

解决:

在该bundle项目的META-INF/MANIFEST.MF文件中,加上一行声明:

Bundle-Activator: com.nariit.sample.kafka.KafkaWebsocketActivator
编译打包后重新启动,activator start()方法执行。


posted @ 2017-08-10 17:12  hongweigg  阅读(52)  评论(0编辑  收藏  举报