osgi实战学习之路:1. ant+bnd+felix搭建osgi之HelloWorld 开发环境分为三个部份 项目主要内容 : 注意: 源码下载


osgi_provider:


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


osgi_consumer:


引用其他bundle


osgi_main:


执行測试


项目主要内容 :


common.xml:



commonuild.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

commonundle.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

源码下载