zoukankan      html  css  js  c++  java
  • 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>
    


    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

    源码下载



  • 相关阅读:
    第十三周课程总结
    第十二周课程总结
    第十一周课程总结
    第十周课程总结
    第九周课程总结 & 实验报告(七)
    第八周课程总结 & 实验报告(六)
    第七周课程总结 & 实验报告(五)
    第六周总结 & 实验报告(四)
    课程总结
    第十四周课程总结&实验报告(简单记事本的实现)
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/7099028.html
Copyright © 2011-2022 走看看