config.ini and org.eclipse.osgi
Dec
源起
在 eclipse PDE 測試 bundle 很方便,實際部署一堆 bundle 時候,執行的情況要如何調整。
參考
部署
一開始是採用 org.eclipse.update.configurator 部署的的自動安裝方式,這個 bundle 啟動後會自動安裝 plugins 目錄下的 bundle,但是並不會啟動這些 bundle,這種部署佈局方式如下。
somedir/
org.eclipse.osgi_3.3.0.v20061101.jar
org.eclipse.update.configurator_3.2.0.v20092006-1400.jar
org.eclipse.equinox.common_3.3.0.v20061023.jar
plugins/
B1.jar
B2.jar
configuration/
config.ini
config.ini 的內容如下,不管後來安裝 B3,B4,B5,X2 等新功能,都不需要 改 config.ini 的內容。
osgi.bundles=org.eclipse.equinox.common@2:start, org.eclipse.update.configurator@3:start eclipse.ignoreApp=true
下面是 eclipse 3.2 sdk 的 config.ini,即使用到數十個 bundle, 也是只要寫三個 bundle 啟動即可。
osgi.bundles=org.eclipse.equinox.common@2:start, org.eclipse.update.configurator@3:start, org.eclipse.core.runtime@start
加 -console 輸出下面內容。
osgi> ss Framework is launched. id State Bundle 0 ACTIVE system.bundle_3.3.0.v20061101 1 ACTIVE org.eclipse.equinox.common_3.3.0.v20061023 2 ACTIVE org.eclipse.update.configurator_3.2.0.v20092006-1400 3 RESOLVED B1_1.0.0 4 RESOLVED B2_1.1.0
可以發現 B1/B2 不會自行啟動。
config.ini 注意事項
- 啟動的檔名很重要,xx@2:start 必須有個 xx-1.2.3.jar 出現,注意如果是 xx_1.2.3.jar 的寫法並不支援。
- 非 eclipse 要加個 eclipse.ignoreApp=true 來啟動。
LazyStart
因為 org.eclipse.update.configurator 只安裝,並不會自動啟動, 可以使用 Eclipse-LazyStart Header 的做法,這樣會讓每個 bundle 被 存取時自動啟動。
Equinox Framework version 3.2 Eclipse-LazyStart: true; exceptions="org.eclipse.foo1" 或是 Equinox Framework version 3.3 Bundle-ActivationPolicy: lazy
但是前提是這些 bundle 有設計這些 header,像是之前做好的一些 bundle 並 不一定有支援這類啟動,這時候需要類似 eclipse sdk 用的 org.eclipse.core.runtime 方式,加一個 runtime 的 bundle 來手動啟動沒有加上 LazyStart 的 bundle。
haha.core.runtime
改由一個新的 haha.core.runtime 統管執行時期的一些調整, 讓讀取的 bundle 可以自動啟動執行。
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
Bundle[] bundles = context.getBundles();
for(Bundle bundle : bundles){
if(bundle.getState() == Bundle.RESOLVED){
bundle.start();
}
}
}
不過上面是一網打盡的做法,會讓加上 Lazy Start 的也執行啟動, 等於枉費 Lazy Start 的設計用意。
config.ini 內容 :
osgi.bundles=org.eclipse.equinox.common@2:start, org.eclipse.update.configurator@3:start, haha.core.runtime@start eclipse.ignoreApp=true
用 Equinox Launcher
下載 launchers-win32.win32.x86.3.3M3.zip 來測試,解開後有下面內容。
root/
eclipse.exe
epl-v10.html
notice.html
startup.jar
configuration/
config.ini
輸出時只要將需要的 jar 放到 plugins 目錄中就可以跑了, 不過這類輸出需要特定平台。
觀察
- 使用 org.eclipse.update.configurator 可以支援讓之前沒寫進 config.ini, 後來加入的 bundle 可以得到啟動。
- Eclipse-LazyStart 可能以後會因為變成標準而改用 Bundle-ActivationPolicy。