首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> Java 程式設計 >> J2EE

OSGi 與 Spring 整合:Spring DM 開發環境建置完整步驟

     編輯:J2EE

本文為《你好,OSGi》系列第六部分。前文介紹 Spring DM 定義,本篇將詳細說明如何建置 Spring DM 開發環境,準備開發首個 Hello World 應用。

Spring DM 開發環境需求

Spring DM 1.0 支援 OSGi Specification Release 4+ 與 JDK 1.4+,經測試相容三大開源 OSGi 容器:Equinox 3.2.2、Felix 1.0.1、Knopflerfish 2.0.3。本文使用 Eclipse 3.3(內建 Equinox 3.3)與 JDK 1.5 測試。Eclipse IDE 對 OSGi Bundle 開發、執行、除錯支援極佳。

環境建置步驟

  1. 下載 Spring DM:撰寫時版本為 1.0.2,下載 spring-osgi-1.0.2-with-dependencies.zip 或最新版
  2. 解壓縮:儲存至如 c:\software
  3. 啟動 Eclipse:選擇空白工作空間如 c:\sample\springdm
  4. 匯入 Spring DM 核心 JAR:
    • Package Explorer 右鍵 Import > Plug-in Development > Plug-ins and Fragments
    • 取消勾選「目標平台」,點擊 Browse 選擇 C:\software\spring-osgi-1.0.2\dist(圖 1)
    • 選擇三個核心外掛:org.springframework.osgi.bundle.core、org.springframework.osgi.bundle.extender、org.springframework.osgi.bundle.io

匯入 Spring DM 核心 JAR

圖 1. 匯入 Spring DM JAR 檔案

  1. 匯入 Spring 相關 Bundle:從 C:\software\spring-osgi-1.0.2\lib 匯入以下七個外掛:
    • org.springframework.bundle.spring.aop
    • org.springframework.bundle.spring.beans
    • org.springframework.bundle.spring.context
    • org.springframework.bundle.spring.core
    • org.springframework.bundle.spring.jdbc
    • org.springframework.bundle.spring.tx
    • org.springframework.osgi.aopalliance.osgi
    • backport-util-concurrent.osgi-3.0-SNAPSHOT.jar(僅 JDK 1.4 需要)

解決 Apache Commons Logging 匯入問題

Spring DM 採用 Apache Commons Logging,提供 OSGi 格式的 Commons Logging 與 Log4j JAR,但 Eclipse 匯入可能失敗。解決方案:自建包含兩個 JAR 的 OSGi 外掛:

  1. File > New > Project > Plug-in Development > Plug-in from existing JAR archives
  2. 點擊 Add External 選擇 commons-logging.jar 與 log4j-1.2.14.jar(圖 2)
  3. 專案名稱輸入 org.apache.commons.logging,Target Platform 選 OSGi Framework > Standard

選擇要包含的 JAR

圖 2. 選擇外掛中要包含的 JAR

至此 Spring DM 開發環境建置完成,下一篇將使用 Spring DM 開發首個 Hello World 應用。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved