开发环境分为三个部份

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. nyoj--767--因子和(模拟)

    因子和 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 题目很简单明了,给你一个数n,判断它是不是素数,如果是素数就输出"Yes",如果不是素数则输出 ...

  2. MVC自定义错误日志异常处理

    MVC添加错误日志处理模块很简单,只要写个继承自HandleErrorAttribute的过滤器,重新OnException方法,贴个异常处理代码如下: public class ExceptionA ...

  3. WLAN 感知

    WLAN 感知 通过 Android 8.0 中新增的 WLAN 感知功能,支持设备可以直接使用 WLAN 感知协议发现其他设备.与其他设备进行互连,以及将覆盖范围扩展到其他设备(Android 9 ...

  4. Linux下通过rdesktop连接Windows远程桌面

    rdesktop是linux下支持Windows远程桌面连接的客户端程序,在linux系统下可通过它远程访问Windows桌面,支持多种版本.rdesktop是sourceforge下支持GPL协议的 ...

  5. [ZJOI2012]旅游 对偶图 树的直径

    Code: // luogu-judger-enable-o2 #include<cstdio> #include<iostream> #include<algorith ...

  6. 为什么使用Nginx & Nginx的使用

    Nginx在Windows平台的配置: 什么是Nginx? 根据前面的对比,我们可以了解到Nginx是一个http服务器.是一个使用c语言开发的高性能的http服务器及反向代理服务器.Nginx是一款 ...

  7. grep常用命令讲解

    grep大家应该并不陌生,但是这个命令你确定真的会用吗?ok,接下来我通过举例子的方式,带你看清grep的本质. 首先,把/etc/password的内容复制下来命令为1.txt吧,方便操作,哈哈~ ...

  8. CSU 1364 Interview RMQ

    题意: 瑶瑶有一家有一家公司,最近他想招m个人.因为他的公司是如此的出名,所以有n个人来参加面试.然而,瑶瑶是如此忙,以至于没有时间来亲自面试他们.所以他准备选择m场面试来测试他们. 瑶瑶决定这样来安 ...

  9. java钩子函数

    也不知道我理解的对不对,欢迎大家讨论! 自己写了个钩子函数,我理解的钩子函数: public interface Transactioner { String wedontknow() ; } pub ...

  10. [Poi] Use Markdown as React Components by Adding a Webpack Loader to Poi

    Poi ships with many webpack loaders included, but you may run into scenarios where you'll need to cu ...