为什么80%的码农都做不了架构师?>>>   

Intro

This tutorial provides an example of how to setup your OSGi project and manage your bundle dependencies using Ant and Ivy. The code and config samples are based on a Eclipse RCP project, but should apply equally to any OSGi project.

The main problem with using Ivy with OSGi bundles, at the time of writing this tutorial, is that many open source project don't ship up-to-date bundles (there are a few exceptions, such as SLF4J). Also, Ivy piggy-backs off Maven repos, which do contain some bundles, but it is still a bit ad-hoc and incomplete.

Another problem is when building an Eclipe RCP application, if you want to create your own Target Platform, you either dump all the RCP SDK bundles into a directory, or you copy them over individually by hand. Both of these methods can be fine for one-off projects, but if you have many projects on the go, each with different dependencies, it all starts to get a bit messy.

This tutorial doesn't go into the detail of how to compile your bundle with Ant, it is assumed you are either using the Eclipse PDE or have already rolled your own build script.

Ant, Ivy and Bundles

The tutorial application will use the following project layout. Thecoyote-bundleandroadrunner-bundleare provided as stubs for the main project implementation, and outside the scope of this tutorial.

Thelibdirectory is used to contain the Antlib-build.xml, which manages the external bundle dependencies for the project. This script is intended as a utility script that will be imported by the two project bundles, rather than being a standalone build script.

  • acme-project

    • coyote-bundle/

      • build.xml
      • ivy.xml
      • ...
    • roadrunner-bundle/
      • build.xml
      • ivy.xml
      • ...
    • lib/
      • bundles/
      • lib-build.xml
      • ivysettings.xml

To add Ivy support, thelib-build.xmlcontains the following targets.

<!-- Provide relative access the lib and bundles dirs from the bundle build scripts. --> <property name="lib.dir" value="${basedir}/../lib"/> <property name="bundles.dir" value="${basedir}/../lib/bundles"/> <!-- Initialize Ivy with our project-wide settings file. --> <target name="lib-init">     <ivy:settings file="${lib.dir}/ivysettings.xml" /> </target> <target name="lib-install-bundles" depends="lib-init">     <mkdir dir="${bundles.dir}"/>     <!-- Load and resolve the ivy dependencies. -->     <ivy:resolve file="${basedir}/ivy.xml"/>     <!-- Retrieve the dependencies -->     <ivy:retrieve pattern="${bundles.dir}/[artifact]-[revision].[ext]" /> </target>

When new bundle dependencies are added to theivy.xmlfile, thelib-install-bundlestarget is used to build theacme-project/lib/bundlesdirectory. This directory can also be used as the root directory for a Target Platform, when developing with the Eclipse PDE.

This is where things start to get a little tricky. Ivy was not really intended to be used for OSGi bundles, because it doesn't support introspection of the bundle meta-data to determine external dependencies.

Thankfully, the Ivy tool is very flexible and transparent, and can fairly easily be made to support bundle dependencies. This is also made easier by the great work done on the SpringSource Enterprise Bundle Repository, where many common open source projects are provided as bundles, and with Ivy<dependency/>snippets to add to yourivy.xmlfiles.

The following shows the content of theivysettings.xmlfile, foracme-project, which uses the Spring framework, and other dependencies provided by the SpringSource repo.

<ivysettings>     <property name="local-cache.dir" value="/workspace/osgi/ivy/local-cache" />     <property name="spring-repo.url" value="http://repository.springsource.com/ivy/bundles" />     <!-- Create a local cache of any downloads, and never delete them. -->     <caches default="localcache">         <cache name="localcache" basedir="${local-cache.dir}">             <ttl duration="0d" />         </cache>     </caches>     <resolvers>         <!-- Build a chain on resolvers, each one is tried in order. -->         <chain name="default" returnFirst="true">             <!-- First try our local cache -->             <filesystem name="local-cache-repo">                 <ivy pattern="${local-cache.dir}/[organisation]/[module]/ivy-[revision].xml" />                 <artifact pattern="${ivy-repo.dir}/[organisation]/[module]/[artifact]-[revision].[ext]" />             </filesystem>             <!-- Then try  -->             <url name="spring-release-repo">                 <ivy pattern="${spring-repo.url}/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />                 <artifact pattern="${spring-repo.url}/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />             </url>             <url name="spring-external-repo">                 <ivy pattern="${spring-repo.url}/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />                 <artifact pattern="${spring-repo.url}/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />             </url>         </chain>     </resolvers> </ivysettings>

Finally, we can declare our project dependencies and Ivy can start to do its thing. Here is the content of theivy.xmlfile for thecoyote-bundle:

<ivy-module>     <info organisation="acme" module="${module.name}" />     <dependencies>        <dependency org="org.apache.commons" name="com.springsource.org.apache.commons.logging" rev="1.1.1"/>         <dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15"/>         <dependency org="org.aopalliance" name="com.springsource.org.aopalliance" rev="1.0.0" />         <dependency org="org.springframework" name="org.springframework.beans" rev="2.5.5.A"/>         <dependency org="org.springframework" name="org.springframework.context" rev="2.5.5.A"/>         <dependency org="org.springframework" name="org.springframework.context.support" rev="2.5.5.A"/>         <dependency org="org.springframework" name="org.springframework.core" rev="2.5.5.A"/>         <dependency org="org.springframework" name="org.springframework.aop" rev="2.5.5.A" />         <dependency org="org.springframework.osgi" name="org.springframework.osgi.core" rev="1.1.0"/>         <dependency org="org.springframework.osgi" name="org.springframework.osgi.extender" rev="1.1.0"/>         <dependency org="org.springframework.osgi" name="org.springframework.osgi.io" rev="1.1.0"/>     </dependencies> </ivy-module>

As you can see in the above, thecoyote-bundlenow has the dependencies required to create a bundle using Spring. As powerful as Spring is, you are still probably going to need more external dependencies if you are building a 'real world' application, especially if it's based on Eclipse RCP.

At this time, there is no Ivy repo that contains up-to-date Eclipse RCP bundles (well, certainly any that I know of). So, as mentioned in the Intro, the options are to download the RCP SDK and dump all the files into theacme-project/lib/bundles, or copy them by hand if you prefer to be a little more precise.

转载于:https://my.oschina.net/yygh/blog/601541

How to use Ivy to manage your OSGi bundle dependen相关推荐

  1. OSGi Bundle之Hello World

    http://developer.51cto.com/art/200909/152209.htm 本文是<你好,OSGi>系列的第二部分.之前曾介绍过OSGi是什么,下面将继续上篇介绍的内 ...

  2. Eclipse中安装插件时提示:No repository found containing: osgi.bundle,org.eclipse.emf,2.8.0.v20180706-1146

    场景 在Eclipse中安装ERMaster时提示: No repository found containing: osgi.bundle,org.eclipse.emf,2.8.0.v201807 ...

  3. ServiceMix中部署:OSGi Bundle和Feature

    http://springsfeng.iteye.com/blog/1392658 ServiceMix中部署:OSGi Bundle和Feature 博客分类: ESB-ServiceMix 部署单 ...

  4. No repository found containing: osgi.bundle,org.tigris.subversion.clientadapter.javahl,1.9.3

    在 Eclipse 安装 SVN 插件 subclipse 1.12 时,多次遇到以下问题: p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px ' ...

  5. JBoss OSGi用户指南(第二章:Getting Started)

    2 Getting Started 2.1 本章内容 This chapter takes you through the first steps of getting JBoss OSGi and ...

  6. java osgi web开发_基于 OSGi 和 Spring 开发 Web 应用

    开发一个简单的OSGi Web应用实例 一个简单的Web应用 我们写一个简单的 Web 应用 compute.html :计算两个数字的和或乘积.如下图所示: 图1.一个简单例子 一个简单例子.bmp ...

  7. OSGI动态加载删除Service bundle

    OSGi模块化框架是很早就出来的一个插件化框架,最早Eclipse用它而出名,但这些年也没有大热虽然OSGi已经发布了版本1到版本5.现在用的最多的,也是本文讲述基于的是Equinox的OSGi实现, ...

  8. 走近Java模块化系统OSGi

    OSGI是什么? 刚入软件开发行业的初哥可能会觉得到处都是值得顶礼膜拜的大神,到处都是复杂到自已无法把握的代码,惊叹这些大神怎样能写出如此神奇的程序出来?! 其实真正好的软件的代码,应该是结构清晰,简 ...

  9. 基于 OSGi 的面向服务的组件编程

    一. OSGi 简史 OSGi 是由 1999 年成立的 OSGi 联盟提出的一个开放的服务规范,最初的目的是为嵌入式设备,确切地说是为可以通过网络访问的设备提供一个通用的软件运行平台,屏蔽不同设备之 ...

最新文章

  1. 循环神经网络实现文本情感分类之使用LSTM完成文本情感分类
  2. java反序列化漏洞实战
  3. 细节之中自有天地,整洁成就卓越代码
  4. 值得关注的AI信息安全公司
  5. isinstance()函数的应用
  6. ios 相册 同时选择多张图片
  7. nc文件的读取与写入
  8. wx小程序 解决子组件样式不起效
  9. Q3面试嵌入式软件工程师的面试经验
  10. 形式化方法:Linear Arithmetic
  11. 树莓派4B EC20 查看4G信号强度
  12. ienumerable vs iqueryable异常
  13. Drawable转Bitmap,Bitmap#getPixel像素为0的解决办法
  14. Pintia(拼题A)刷题插件 on VS Code
  15. python远程安装软件_在家想远程公司电脑?Python + 微信一键连接!
  16. Grails – GORM教程
  17. 玩转CVM:Web服务搭建
  18. Python入门系列(十一)一篇搞定python操作MySQL数据库
  19. 4399笔试面试——感受
  20. [LAMPP] 低成本搭建一个个人PHP经营性网站 (StepByStep)

热门文章

  1. Python中类的介绍及使用
  2. 【回归分析】MATLAB实现多元线性/非线性回归
  3. 2021神木四中罗超同学高考成绩查询,2021衡阳市地区高考成绩排名查询,衡阳市高考各高中成绩喜报榜单...
  4. 马自达的VE历史与基本GVE概念
  5. windows10系统下快速安装SqlServer教程
  6. 如何无需开发集成易快报、金蝶等第三方应用
  7. 开挂进大厂:BATJ面试官能问到的Java面试题,都被打包在这份PDF文档里
  8. 灰尘静电会影响到什么?
  9. Atmel Studio 6.0 SP2 2.4 Gb.txt
  10. k8s还能这么玩?快速上手物联网应用的容器开发