Gemini Blueprint应用
1. Gemini Blueprint环境搭建
1.0. Gemini blueprint环境下载
个人建议下载virgo环境,而不是下载Gemini web开发包。
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_helloworld和springdm_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:
步骤7:在springdm_helloworld/META-INF目录下创建spring目录(如步骤2展示的项目树结构),并在spring目录下创建两个XML文件,分别是:helloworld-spring-osgi.xml和helloworld-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.1搭建Gemini Server环境类似。
步骤10:在osgi>命令环境输入“ss”,列表出当前OSGi运行环境中的plug-in包。可以看到plug-in id为56和57的已经是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 57和osgi> 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;
}
}
步骤3:META-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 应用