開發含有簡式啟動的 OSGi 軟體組

控制 OSGi 軟體組程式碼的生命週期,最直接明確的方式是在您的軟體組的其中一個類別中實作 org.osgi.framework.BundleActivator 介面。 當伺服器啟動及停止軟體組時,會呼叫 BundleActivator 介面的 start 和 stop 方法。

關於這項作業

如果您使用 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
	}
}

指示主題類型的圖示 作業主題

檔名:twlp_bundle_simple_activation.html