eclipse and OSGi

0

源起

想開發基於 RCP 之上的應用,就需要了解其底層使用的 OSGi 運作機制。OSGi 基本上希望軟體可以像現在 USB 一樣熱插拔,既然 USB 需要 OS 支援,應用程式就需要 OSGi 來做這個事,讓符合規格的應用程式可以直接熱插拔,甚至可以挑版本插拔,聽起來好像不錯。

What’s New

  1. 2006-09-23 新增螢幕展示 screencast

Open Services Gateway in Eclipse

大部分的 Java 開發者都直接用 IDE,並不太會去動到 eclipse 的內部,eclispe IDE 本身由一堆 plug-ins 組成,同時提供一個 OSGi 的環境供 plug-ins 運作,提供整個開發所需的功能。

慢慢地有人覺得 minimum eclipse plug-ins 可以方便再利用來開發 eclipse IDE 類似桌面型軟體,所以 Eclipse Rich Client Platform (RCP) 慢慢成形,RCP 牽涉到 plug-ins 取捨,選哪些 eclipse plug-ins 可以方便以後大家使用,當然 OSGi 也要一起包起來帶走。

RCP 包起來的環境中都可以找到這個實作 rcp/plugins/org.eclipse.osgi_3.x.x.jar。

osgi console

先進入 console 狀態

C:\Downloads\EclipseInstall\OSGi>java -Dosgi.install.area=file://c:/downloads/ 
-cp org.eclipse.osgi_3.2.0.v20060601.jar
org.eclipse.osgi.framework.launcher.Launcher -console

launch 後到 http://www.knopflerfish.org/repo/index.html 找一些下載。

osgi> ss

Framework is shutdown.

id      State       Bundle
0       RESOLVED    system.bundle_3.2.0.v20060601

osgi> launch

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601

osgi> install http://www.knopflerfish.org/repo/jars/log/log_all-2.0.0.jar
Bundle id is 1

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0

osgi> start 1

啟動失敗,會告知缺少 org.osgi.service.cm,換一個不相依commons-logging_all-2.0.0.jar 試過,可以啟動。

osgi> install http://www.knopflerfish.org/repo/jars/commons-logging/commons-logging_all-2.0.0.jar
Bundle id is 2

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0
2       INSTALLED   org.knopflerfish.bundle.commons-logging_2.0.0

osgi> start 2

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0

加上 cm 看看。

osgi> install http://www.knopflerfish.org/repo/jars/cm/cm_all-2.0.0.jar
Bundle id is 4

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       INSTALLED   org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0
4       INSTALLED   org.knopflerfish.bundle.cm_2.0.0

osgi> start 4

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       RESOLVED    org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0
4       ACTIVE      org.knopflerfish.bundle.cm_2.0.0

osgi> start 1

osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.v20060601
1       ACTIVE      org.knopflerfish.log_2.0.0
2       ACTIVE      org.knopflerfish.bundle.commons-logging_2.0.0
4       ACTIVE      org.knopflerfish.bundle.cm_2.0.0

screencast 螢幕展示

覺得手動太麻煩 ? 可以用 eclipse 來玩,非常簡單,幾分鐘就可以。

screencast

  1. 用 3.2 版
  2. 只有選 plug-in 專案,沒有 Bundle 專案,以後也許會改比較 OSGi 的說法。
  3. 用 Equinox 當底層
  4. 都幫你出好了,雖然應該用 Bundle 比較適合
  5. 直接用範本,連程式碼都不用打
  6. 直接就可以跑
  7. 檢視一下
  8. 匯出 jar
  9. 順便匯出 ant 的 build.xml 參考
  10. 看一下成果
  11. 建立一個純的 osgi 環境,只取 org.eclipse.osgi 一個 jar
  12. 直接吃剛才編出的 jar 看看。

產出的 ant build.xml 可是好東西,對於需要 自動化產出 Bundle 的人來說,用起來會很方便。

small osgi 螢幕展示

關於 eclipse 開發的螢幕展示還可以參考下面連結,將 OSGi 環境建立在改造過小型 NAS 裝置上面,在遠端用 eclipse 開發。

Coding bundles on the Slug demo movie

Remote debugging on the Slug demo movie

OSGi 移植到小裝置上的做法,也許 gcj 也是一種可以考慮的做法。

OpenSlug Gateway Installation – OSGi on the NSLU2

OSGi on the Slug

將 OSGi 真的變成 Open Services Gateway 似乎需要一點時間,目前 IBM 在這個領域推蠻久的。

Managed mobile clients with OSGi: Managed smart clients

IBM Workplace Client Technology, Micro Edition and Open Services Gateway Initiative

links 參考

Developing Eclipse/OSGi Web Applications

OSGi Everywhere

Spring and OSGi, A Perfect Match?

Spring and OSGi

Understanding how Eclipse plug-ins work with OSGi

Launching Eclipse OSGi Framework from the command line

OSGi Open Source Market

Knopflerfish – Open Source OSGi

Java: 淺談 OSGi 標準

eclipse rcp editor

0

針對 Eclipse 的 RCP 平台做的練習。

主要根據 Tom Eicher 的 簡報 來修改練習。

線上資源 : Platform Plug-in Developer Guide / The Official Eclipse FAQs

editor screencast 1

Syntax coloring 練習,針對特定文字做加深的效果。

editor screencast 2

Syntax coloring 練習,針對一整行處理,例如:之後直到斷行為藍色,字首 (NUM) 改為紅色。

editor screencast 3

Syntax coloring 練習,針對一區 partition 處理。

editor screencast 4

Content Assist 練習,實做 IContentAssistProcessor 並內建 Template 物件。

editor screencast 5

Content Assist 練習,使用 editor.Templates 延伸,直接將樣式寫在 plugin.xml 中。

editor screencast 6

Older posts: 1 2 3 4