OSGi与Spring:设置Spring DM开发环境

【51CTO精选译文】本文是《你好,OSGi 》系列的第 六部分。之前我们介绍了什么是Spring动态模型(Spring DM) , 下面我们将学习如何设置Spring DM开发环境,并准备使用Spring DM开发您的第一个Hello World应用。

51CTO编辑推荐: OSGi入门与实践全攻略

设置Spring DM开发环境

Spring DM框架 1.0(Spring Dynamic Modules framework 1.0 )支持与 OSGi Specification Release 4(或更高版本)以及 JDK 1.4(或更高版本)兼容的 OSGi 套件的开发。Spring DM还针对三个开源 OSGi 容器实施(Equinox 3.2.2、Felix 1.0.1 和 Knopflerfish 2.0.3)进行了测试,所以你可以在这三个容器实施中执行你的代码。

在 本节的开发示例中,我使用了 Eclipse 3.3,它嵌入了 Equinox 3.3 OSGi 容器。Eclipse IDE 为 OSGi 套件的开发、执行和调试提供很好的支持。我使用 JDK 1.5 测试了本节中的示例代码。请按照以下步骤使用 Eclipse IDE 设置开发环境:

1. 下载 Spring DM。写作本文时,其发布版本为 1.0.2。请确保下载 spring-osgi-1.0.2-with-dependencies.zip 或最新的zip文件。

2. 解压缩 spring-osgi-1.0.2-with-dependencies.zip ,将其内容保存在你的计算机上,比如可保持到 c:/software 文件夹中。

3. 启动 Eclipse IDE。但需要选择工作空间(workspace),请选择空文件夹,比如 c:/sample/springdm。

4. 导入该项目所需的所有 Spring DM JAR 文件。在 Package Explorer 上右击,然后点击 Import --> Plug-in Development --> Plug-ins and Fragments,然后单击下一步,将弹出 Import Plug-ins and Fragments 对话框。

5. 在该对话框中,取消选择目标平台复选框(在 Preferences 中指定)。

6. Plug-in Location 的浏览(Browse)按钮现在应该是激活状态;单击它,然后选择 C:/software/spring-osgi-1.0.2/dist,如图1 所示。

导入 Spring DM JAR 文件  

图1.导入 Spring DM JAR 文件

7. 单击下一步,弹出 Selection 对话框;将以下三个插件添加到你的“Plug-ins and Fragments to import”中:

1. org.springframeork.osgi.bundle.core 
2. org.springframeork.osgi.bundle.extender 
3. org.springframeork.osgi.bundle.io

现在单击完成。Eclipse 会将这三个套件导入到你的工作空间中,在那里你应能够在 Package Explorer 视图中看到它们。

8. 下一步,你要从 C:/software/spring-osgi-1.0.2/lib 再导入几个套件,所以请返回并重复步骤 4 和步骤 5。在步骤 6 中,选择插件位置(plug-in location)为:C:/software/spring-osgi-1.0.2/lib,然后单击下一步。

9. 在 Selection 对话框中,你将会看到更多能够使用的插件,请选择以下插件:

    1. org.springframeork.bundle.spring.aop 
    2. org.springframeork.bundle.spring.beans 
    3. org.springframeork.bundle.spring.context 
    4. org.springframeork.bundle.spring.core 
    5. org.springframeork.bundle.spring.jdbc 
    6. org.springframeork.bundle.spring.tx 
    7. org.springframeork.osgi.aopalliance.osgi 
    8. backport-util-concurrent.osgi-3.0-SNAPSHOT.jar (if you're using JDK 1.4)

选择完成之后,请单击完成,Eclipse 会将这七个套件导入到你的工作空间中。

Apache Commons Logging 是 Spring DM的日志框架。Spring DM提供了OSGi 套件格式的 Apache Commons Logging 以及 Apache Log4j JAR。不过,这些套件好像有些问题,因为我使用 Eclipse 无法将他们导入。如果你遇到同样的问题,请按照以下步骤,创建你自己的 OSGi 套件,其中包含了这两个 JAR:

1. 在 Eclipse 中,单击 File --> New --> Project -> Plug-in Development --> Plug-in from existing JAR archives,然后点击下一步。Eclipse 将打开 JAR Selection 对话框。

2. 在该对话框中,单击 Add External 按钮,弹出 File Selection 对话框。此处,你可以选择 commons-logging.jar 和 log4j-1.2.14.jar。你的 JAR Selection 对话框有与图2中的截图类似。

选择插件中要包含的 JAR  

图2. 选择插件中要包含的 JAR

单击下一步,Eclipse 将弹出 Plug-in Project Properties 对话框。

3. 在 Plug-in Project Properties 对话框中,请输入项目名称——与 org.apache.commons.logging 类似。在 Target Platform 部分,请选择 OSGi Framework --> Standard,然后单击完成。

设置Spring DM开发环境的步骤就是这样,开发 Spring DM插件所需的 Eclipse 环境已经准备完毕。在下面一篇文章中,我们将使用 Spring DM来开发一个 Hello World 应用程序。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值