开发环境分为三个部份

osgi_provider:

bundle开发环境,对外提供服务

osgi_consumer:

引用其他bundle

osgi_main:

执行測试

项目主要内容 :

common.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="common">
<!--
属性定义
-->
<dirname property="root.dir" file="${ant.file.common}" />
<property file="${root.dir}/common/build.properties" /> <path id="external.classpath" >
<fileset dir="${lib.dir}" includes="*.jar" />
</path>
<!-- dist -->
<taskdef resource="aQute/bnd/ant/taskdef.properties" classpath="${bnd.jar}"/>
<target name="dist" depends="compile" >
<echo>dist...</echo>
<pathconvert pathsep="," dirsep="/" property="-classpath" refid="external.classpath"/>
<!-- 利用bnd工具生成 bundle-->
<bnd files="${root.dir}/common/bundle.properties" classpath="${build.classes.dir}"/>
<!-- 拷贝到client,main的lib中-->
<copy todir="${to_client_lib.dir}" >
<fileset dir="${build.dist.bundles.dir}" includes="*.jar" ></fileset>
</copy>
<copy todir="${to_main_lib.dir}" >
<fileset dir="${build.dist.bundles.dir}" includes="*.jar" ></fileset>
</copy>
</target>
<!-- clean-->
<target name="clean">
<echo>clean...</echo>
<delete dir="${build.dir}"/>
</target>
<!-- init-->
<target name="init" depends="clean">
<echo>init...</echo>
<mkdir dir="${build.dir}" />
<mkdir dir="${build.src.dir}" />
<mkdir dir="${build.classes.dir}" />
<mkdir dir="${build.dist.dir}" />
<mkdir dir="${build.dist.bundles.dir}" />
</target>
<!-- compile-->
<target name="compile" depends="init">
<echo>compile ...</echo>
<property name="compile.level" value="1.5" />
<!-- 编译-->
<javac srcdir="${src.dir}" destdir="${build.classes.dir}"
debug="on"
source="${compile.level}"
target="${compile.level}"
includeantruntime="false">
<classpath>
<path refid="external.classpath" />
<fileset dir="${build.dist.bundles.dir}" includes="*.jar" />
</classpath>
</javac>
<!-- 复制src-->
<copy todir="${build.src.dir}" includeEmptyDirs="false">
<fileset dir="${src.dir}" includes="**/*.*"/>
</copy>
</target> </project>

common\build.properties:

build.xml中属性配置

#-------------------------------------------------
#------------------------------------------------- src.dir=src
lib.dir=lib
build.dir=build
build.src.dir=${build.dir}/src
build.classes.dir=${build.dir}/classes
build.dist.dir=${build.dir}/dist
build.dist.bundles.dir=${build.dist.dir}/bundles
build.test.dir=${build.dir}/test
#copy bundle to osgi_consumer/lib
to_client_lib.dir=../osgi_consumer/lib
#copy bundle to osgi_main/lib
to_main_lib.dir=../osgi_main/lib
bnd.jar=${lib.dir}/bnd-0.0.384.jar Bundle-Name: ${ant.project.name}
Bundle-SymbolicName: ${module}
Bundle-Version: ${version}
Bundle-DocURL: http://code.google.com/p/osgi-in-action/
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 version: 1.0 -versionpolicy:"[$(version;\=\=;$(@)),$(version;+;$(@)))" Include-Resource:META-INF/LICENSE\=${root.dir}/LICENSE-ASL.txt,META-INF/NOTICE\=${root.dir}/NOTICE -output:\
${build.dist.bundles.dir}/${ant.project.name}-${version}.jar -removeheaders:\
Private-Package,Include-Resource

common\bundle.properties

bundle的描写叙述信息

module=com.demo.hello
custom=true Export-Package:${module};version\="2.0" Import-Package:org.osgi.framework;version\="[1.3,2.0)",${module};version\="[2.0,3.0)"

注意:

  • 将lib下的包加入到build path中
  • bundle的创建由bnd来运行
  • osgi_provider会将创建的bundle拷贝到osgi_consumer,osgi_main
  • osgi_consumer会将创建的bundle拷贝到osgi_main

源码下载

osgi实战学习之路:1. ant+bnd+felix搭建osgi之HelloWorld的更多相关文章

  1. osgi实战学习之路:2. maven+maven-bundle-plugin+karaf搭建osgi之HelloWorld

    环境准备: jdk版本号 jdk:1.7 karaf: 版本号:apache-karaf-3.0.1 下载地址: http://pan.baidu.com/s/1qWM4Y1u http://kara ...

  2. osgi实战学习之路:4.Bundle

    </pre></h1><h1 style="margin:0 0 0 40px; border:none; padding:0px"><p ...

  3. osgi实战学习之路:8. Service-3之ServiceTracker

    通过ServiceTracker能够对查找的Service进行扩展 以下的demo引入装饰器模式对Service进行日志的扩展 demo: Provider student-manage/Activa ...

  4. osgi实战学习之路:5.生命周期及利用命令、装饰者模式实现基于socket交互Bundle命令demo

    生命周期中关键3个类: BundleActivator 入口点,类似main方法 BundleContext Bundle上下文对象,在执行期间,为应用程序提供操作osgi框架的方法 Bundle 代 ...

  5. osgi实战学习之路:3. osgi分层概念及相互合作demo

    源码下载 分层: modual: 主要作用于包级管理与共享代码 lifecycle: 主要作用于执行期间的模块管理与訪问osgi底层框架 service: 主要作用于多模块之间的相互通信 demo: ...

  6. osgi实战学习之路:6. Service-1

    什么是Service? 它是注冊到osgi的一个java对象 Service注冊: 通过BundleContext::registerService(java.lang.String[] clazze ...

  7. C++学习之路——1.linux下环境搭建

    学习之路,可说各有各的看法和方法.对于我来说,完全是兴趣一下子来了,脑壳发热吧.就想有个干净的环境,只想着与程序有关的东西练一练. 目前想学习C++,可是打开VC++6,再安了VS2010.VS201 ...

  8. [原创]java WEB学习笔记54:Struts2学习之路---概述,环境的搭建

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  9. springcloud学习之路: (一) 最简单的搭建springcloud的方法

    参考资料: [JavaEE] 五分钟搭建SpringCloud环境, 进入微服务时代 感谢上篇博文大佬带领走进springcloud世界, 本博文主要目的为记录自己学习springcloud的点点滴滴 ...

随机推荐

  1. springBoot 打war包 程序包com.sun.istack.internal不存在的问题

    使用的是 idea - Lifecycle-package 的方式打包(maven) 确认  <packaging>war</packaging> 修改启动类: (原启动类) ...

  2. 将ubuntu安装在用剩下的硬盘改装成的移动硬盘时遇到的问题及解决办法

    安装时分完盘后提示:“分配到/的分区开始于3584字节,使用磁盘的最小对齐,这可能造成非常差的性能..." 解决办法: 回到windows使用分区助手等工具先分好盘而不是在安装时分盘(这样分 ...

  3. 互不侵犯_状压$dp$

    如果有想学习状压\(dp\)的童鞋,请光临博客状压\(dp\)初学 互不侵犯 题目描述 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八 ...

  4. Java获取电脑硬件信息

    package com.szht.gpy.util; import java.applet.Applet; import java.awt.Graphics; import java.io.Buffe ...

  5. Element UI的Table用法

    Table 表格 用于展示多条结构类似的数据,可对数据进行排序.筛选.对比或其他自定义操作. ¶基础表格 基 2016-05-02 王小虎 上海市普陀区金沙江路 1518 弄 2016-05-04 王 ...

  6. HTML5按键打开摄像头和拍照

    HTML5实现按键打开摄像头和拍照 步骤: 1.创建一个打开摄像头按钮的标签.video标签.拍照的按钮标签.画布 2.实现打开摄像头的功能 3.实现拍照功能   具体实现代码: <!DOCTY ...

  7. unity 天空盒有缝隙的解决方案

    修改天空盒图片的属性:advanced->wrap mode->clamp

  8. [Python] Slice the data with pandas

    For example we have dataframe like this: SPY AAPL IBM GOOG GLD 2017-01-03 222.073914 114.311760 160. ...

  9. CSS3绘制砖墙-没实用不论什么图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. c++动态库中使用命名空间的问题

    这是C++才会有的语言特性. 假如你使用一个程序库,他里面有桓霰淞拷衋bc,可是你自己也不小心定义了一个叫abc的变量,这样就会引起重定义错误.所以为了避免这样的现象,C++引入了名字空间(names ...