开发环境分为三个部份

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. word 的使用 —— 分页符与分节符

    节的概念:节定义了一些格式, 如页边距.页面的方向.页眉和页脚,以及页码的顺序. 分节符是指为表示节的结尾插入的标记. 分节符的作用: 分节符起着分隔其前后文本格式的作用,如果删除了某个分节符,它前面 ...

  2. BZOJ3261 最大异或和 解题报告(可持久化Trie树)

    本题链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3261 题目描述 给定一个非负整数序列{a},初始长度为N. 有M个操作,有以下两种操作类 ...

  3. js运算符单竖杠“|”与“||”的用法和作用介绍

    在js开发应用中我们通常会碰到“|”与“||”了,那么在运算中“|”与“||”是什么意思呢?   在js整数操作的时候,相当于去除小数点,parseInt.在正数的时候相当于Math.floor(), ...

  4. 洛谷3964 [TJOI2013]松鼠聚会

    题目描述 草原上住着一群小松鼠,每个小松鼠都有一个家.时间长了,大家觉得应该聚一聚.但是草原非常大,松鼠们都很头疼应该在谁家聚会才最合理. 每个小松鼠的家可以用一个点x,y表示,两个点的距离定义为点( ...

  5. caioj 1077 动态规划入门(非常规DP1:筷子)

    首先可以看出排序之后,最优解肯定是每一对都相邻才是最优的 那么我们就要找构成最优解的相邻组 设f[i][j]是前i个字符,k对的最小值 如果当前这个筷子不取的话,f[i][j] = f[i-1][j] ...

  6. Haproxy压测

    目的:测试Haproxy压测情况 环境: Ha服务器:8核16G虚机,后端6个2核4G,压测客户端3个2核4G 安装和优化: 一.Haproxy #cd /opt/soft #wget http:// ...

  7. Redis封装之Set

    RedisSetService: /// <summary> /// Set:用哈希表来保持字符串的唯一性,没有先后顺序,存储一些集合性的数据 /// 1.共同好友.二度好友 /// 2. ...

  8. Function的一些结论与eval函数.

    1.1 函数的创建方式 1 函数声明 2 函数表达式 3 new Function // 1 function foo() {} // 2 var foo = function() {}; // 3 ...

  9. 公司采购 流程flowable例子

    Name: Flowable BPMN 2.0 designer Location: http://flowable.org/designer/update/ 业务描述:1. 公司采购,因为办公用品价 ...

  10. 简单的quartz 可视化监听管理界面

    spring-quartz. 导包.配置,不在此介绍. 简单的quartz管理界面,包括触发器的暂停.恢复.删除.修改(暂无),任务的运行.触发添加.创建,删除. 扩展内容:日志的管理,添加和创建触发 ...