osgi gemini blueprint环境


Gemini Blueprint应用

 

 

1.  Gemini Blueprint环境搭建

 

1.0.  Gemini blueprint环境下载

个人建议下载virgo环境,而不是下载Gemini web开发包。

 http://www.eclipse.org/downloads/download.php?file=/virgo/release/VP/3.6.3.RELEASE/virgo-tomcat-server-3.6.3.RELEASE.zip&mirror_id=1071

 

1.1.  搭建Gemini Server

步骤1

步骤2

 

 

步骤3

 

步骤4

步骤5

步骤6,添加运行环境的目录

步骤7

步骤8:下面这几个包需要手动选择添加。

 

1.2.  配置plug-in development

激活目标平台。

步骤1:打开window->preferences->Plugin-in Development->Target Platform

步骤2:选中目标平台,然后按下“Reload”,最后点击“Apply””OK”

2.  Gemini HelloWorld

 

2.1.  HelloWorld Service

步骤1创建两个Plug-in项目,项目名称分别为:springdm_helloworldspringdm_client

步骤2展开两个项目树如下图

 

步骤3添加HelloWorld.java代码

package springdm.helloworld;

 

publicinterface HelloWorld

{

    String sayHello(String name);

}

 

 

步骤4添加HelloWorld的实现代码

package springdm.helloworld;

 

publicclass HelloWorldImpl implements HelloWorld

{

 

    @Override

    public String sayHello(String name)

    {

       return"Hello "+name;

    }

 

}

 

步骤5

步骤6

步骤7springdm_helloworld/META-INF目录下创建spring目录(如步骤2展示的项目树结构),并在spring目录下创建两个XML文件,分别是:helloworld-spring-osgi.xmlhelloworld-spring.xml。内容分别为:

 

helloworld-spring-osgi.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi"

    xsi:schemaLocation="

  http://www.springframework.org/schema/beans

  http://www.springframework.org/schema/beans/spring-beans.xsd

  http://www.springframework.org/schema/osgi

  http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <osgi:service interface="springdm.helloworld.HelloWorld" ref="helloWordService"  />

</beans>

 

helloworld-spring.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi"

    xsi:schemaLocation="

  http://www.springframework.org/schema/beans

  http://www.springframework.org/schema/beans/spring-beans.xsd

  http://www.springframework.org/schema/osgi

  http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <bean id="helloWordService" class="springdm.helloworld.HelloWorldImpl" />

</beans>

 

步骤8运行

 

步骤9配置Plugin-in运行环境,此步骤与1.1Gemini Server环境类似。

步骤10:在osgi>命令环境输入“ss”,列表出当前OSGi运行环境中的plug-in包。可以看到plug-in id5657的已经是ACTIVE状态。

osgi> ss

"Framework is launched."

 

 

id  State       Bundle

0   ACTIVE      org.eclipse.osgi_3.9.1.v20140110-1610

                Fragments=23, 28

………

 

55  ACTIVE      javax.servlet.jsp_2.2.0.v201112011158

56  ACTIVE      springdm_client_1.0.0.qualifier

57  ACTIVE      springdm_helloworld_1.0.0.qualifier

 

步骤11继续输入 osgi> b 57osgi> b 56,显示plug-in的详细信息。要能看到如下图显示出来的结果。通过gemini blueprint注册的服务。

2.2.  HelloWorld Client

前面某些步骤是相似的,就不再赘述了。下列步骤列出一些不同点。

步骤1添加依赖springdm.helloworld

步骤2添加Client代码

package springdm_client;

 

import org.osgi.framework.Bundle;

 

import springdm.helloworld.HelloWorld;

 

publicclass Client

{

    private HelloWorld helloWorld;

   

    private Bundle hw;

   

    publicvoid init(){

       System.out.println(helloWorld.sayHello("client"));

       System.out.println(hw.getHeaders().toString());

    }

 

    public HelloWorld getHelloWorld()

    {

       returnhelloWorld;

    }

 

    publicvoid setHelloWorld(HelloWorld helloWorld)

    {

       this.helloWorld = helloWorld;

    }

 

    publicvoid setHw(Bundle hw)

    {

       this.hw = hw;

    }

}

 

步骤3META-INF/spring目录下的文件内容

 

client-spring-osgi.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns:osgi="http://www.springframework.org/schema/osgi"

    xsi:schemaLocation="

  http://www.springframework.org/schema/beans

  http://www.springframework.org/schema/beans/spring-beans.xsd

  http://www.springframework.org/schema/osgi

  http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <osgi:reference id="hello" interface="springdm.helloworld.HelloWorld" />

    <osgi:bundle id="hw" symbolic-name="org.eclipse.gemini.blueprint.extender"></osgi:bundle>

</beans>

 

client-spring.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns:osgi="http://www.springframework.org/schema/osgi"

    xsi:schemaLocation="

  http://www.springframework.org/schema/beans

  http://www.springframework.org/schema/beans/spring-beans.xsd

  http://www.springframework.org/schema/osgi

  http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <bean id="client" class="springdm_client.Client" init-method="init">

        <property name="helloWorld" ref="hello" />

        <property name="hw" ref="hw" />

    </bean>

</beans>

 

步骤4需要将两个包勾起来,在同一个环境中运行。

 

控制台结果:

osgi> Hello client

[Ljava.lang.Object;@1b32627

 

3.  Gemini WEB 应用

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值