osgi实战学习之路:1. ant+bnd+felix搭建osgi之HelloWorld

开发环境分为三个部份


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

源代码下载



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值