단순 활성화로 OSGi 번들 개발
OSGi 번들 코드의 라이프사이클을 제어하는 가장 간편한 방법은 번들 내의 클래스 중 하나에서 org.osgi.framework.BundleActivator 인터페이스를 구현하는 것입니다. 서버가 번들을 시작하고 중지할 때 BundleActivator 인터페이스의 시작 및 중지 메소드가 호출됩니다.
이 태스크 정보
WebSphere® Application Server Developer Tools를 사용하고 있는 경우, OSGi 번들 프로젝트를 작성하고 이 프로젝트에서 OSGi BundleActivator 클래스를 작성하십시오. 그런 후 Bundle-Activator 헤더를 번들 MANIFEST.MF 파일에 추가하여 OSGi 프레임워크가 사용자의 번들 활성화기 클래스를 식별하도록 하십시오. 예: Bundle-Activator: com.example.bundle.Activator
예제
package com.example.bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
System.out.println("Sample bundle starting");
// Insert bundle activation logic here
}
public void stop(BundleContext context) throws Exception {
System.out.println("Sample bundle stopping");
// Insert bundle deactivation logic here
}
}