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

osgi gemini blueprint环境

步骤2

 osgi gemini blueprint环境

 

步骤3

osgi gemini blueprint环境

 

步骤4

osgi gemini blueprint环境

步骤5

osgi gemini blueprint环境

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

osgi gemini blueprint环境

步骤7

osgi gemini blueprint环境

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

osgi gemini blueprint环境

 

1.2.  配置plug-in development

**目标平台。

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

osgi gemini blueprint环境

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

osgi gemini blueprint环境

2.  Gemini HelloWorld

 

2.1.  HelloWorld Service

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

osgi gemini blueprint环境

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

osgi gemini blueprint环境

 

步骤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

osgi gemini blueprint环境

步骤6

osgi gemini blueprint环境

步骤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运行

osgi gemini blueprint环境

 

步骤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注册的服务。

osgi gemini blueprint环境

2.2.  HelloWorld Client

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

步骤1添加依赖springdm.helloworld

osgi gemini blueprint环境

步骤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 gemini blueprint环境

 

控制台结果:

osgi> Hello client

[Ljava.lang.Object;@1b32627

 

3.  Gemini WEB 应用

 

相关文章: