1 前言
1.1 本指南基于 OSGi.基于Spring,Hibernate的Web应用快速开发指南,所以开发中的某些具体步骤将省略,只具体到文件。
1.2 本指南将开发三个Bundle
com.dw.calc.service Bundle,发布接口ICalcService,接口功能为返回两个整数的和
com.dw.calc.service.impl Bundle,实现接口ICalcService接口
com.dw.calc.client Bundle,实现OSGi远程服务调用ICalcService接口
2 下载ECF SDK
http://ftp.cs.pu.edu.tw/pub/eclipse/rt/ecf/3.5.6/org.eclipse.ecf.sdk_3.5.6.v20120610-1946.zip
3 安装 ECF Bundle 依赖到 virgo-tomcat 服务器
解压ECF SDK,复制org.eclipse.ecf.sdk\plugins目录下的所有.jar结尾的Bundles,拷贝到virgo-tomcat-server\repository\usr目录下
本指南中依赖的的bundle包基本都是从
http://ebr.springsource.com/repository/app/下载
org.eclipse.ecf.springframework这个Bundle从git://git.eclipse.org/gitroot/ecf/org.eclipse.ecf.git获取,git的使用我就省略了,请直接
下载,下载回来后改后缀名为.jar
4 开发 Bundle com.dw.calc.service4.1 src/META-INF/MANIFEST.MF Manifest-Version: 1.0
Manifest-Version: 1.0
 Bundle-Version: 1.0.0
Bundle-Version: 1.0.0
 Bundle-Name: Service
Bundle-Name: Service
 Bundle-ManifestVersion: 2
Bundle-ManifestVersion: 2
 Bundle-SymbolicName: com.dw.calc.service
Bundle-SymbolicName: com.dw.calc.service
 Export-Package: com.dw.calc.service
Export-Package: com.dw.calc.service package com.dw.calc.service;
package com.dw.calc.service;


 public interface ICalcService
public interface ICalcService  {
{
 public Integer plus(Integer i1, Integer i2);
    public Integer plus(Integer i1, Integer i2);
 }
}
5.1 src/com.dw.calc.service.ICalcService.CalcServiceImpl.java package com.dw.clac.service.impl;
package com.dw.clac.service.impl;

 import com.dw.calc.service.ICalcService;
import com.dw.calc.service.ICalcService;


 public class CalcServiceImpl implements ICalcService
public class CalcServiceImpl implements ICalcService {
{

 @Override
    @Override

 public Integer plus(Integer i1, Integer i2)
    public Integer plus(Integer i1, Integer i2)  {
{
 return i1 + i2;
        return i1 + i2;
 }
    }

 }
} Manifest-Version: 1.0
Manifest-Version: 1.0
 Export-Package: com.dw.clac.service.impl;uses:="com.dw.calc.service"
Export-Package: com.dw.clac.service.impl;uses:="com.dw.calc.service"
 Bundle-Version: 1.0.0
Bundle-Version: 1.0.0
 Tool: Bundlor 1.1.0.RELEASE
Tool: Bundlor 1.1.0.RELEASE
 Bundle-Name: Impl
Bundle-Name: Impl
 Bundle-ManifestVersion: 2
Bundle-ManifestVersion: 2
 Import-Package: com.dw.calc.service,
Import-Package: com.dw.calc.service,
 org.eclipse.ecf.core;version="[3.0.0,3.0.0]",
 org.eclipse.ecf.core;version="[3.0.0,3.0.0]",
 org.eclipse.ecf.springframework,
 org.eclipse.ecf.springframework,
 org.eclipse.ecf.springframework.identity,
 org.eclipse.ecf.springframework.identity,
 org.eclipse.equinox.app;version="[1.1.0,1.1.0]"
 org.eclipse.equinox.app;version="[1.1.0,1.1.0]"
 Bundle-SymbolicName: com.dw.calc.service.impl
Bundle-SymbolicName: com.dw.calc.service.impl
 Import-Bundle: org.eclipse.ecf.provider;version="[4.2.100.v20120610-1946,4.2.100.v20120610-1946]"
Import-Bundle: org.eclipse.ecf.provider;version="[4.2.100.v20120610-1946,4.2.100.v20120610-1946]" <?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
<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"
    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
    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">
                      http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">

 <osgi:reference id="containerFactory" interface="org.eclipse.ecf.core.IContainerFactory" timeout="1000" cardinality="1..1" />
    <osgi:reference id="containerFactory" interface="org.eclipse.ecf.core.IContainerFactory" timeout="1000" cardinality="1..1" />

 <bean class="org.eclipse.ecf.springframework.HostContainerFactoryBean">
    <bean class="org.eclipse.ecf.springframework.HostContainerFactoryBean">
 <property name="containerType" value="ecf.generic.server" />
        <property name="containerType" value="ecf.generic.server" />
 <property name="containerFactory" ref="containerFactory" />
        <property name="containerFactory" ref="containerFactory" />
 </bean>
    </bean>

 <osgi:service interface="com.dw.calc.service.ICalcService">
    <osgi:service interface="com.dw.calc.service.ICalcService">
 <osgi:service-properties>
        <osgi:service-properties>
 <entry key="service.exported.interfaces" value="*" />
            <entry key="service.exported.interfaces" value="*" />
 <entry key="service.exported.configs" value="ecf.generic.server" />
            <entry key="service.exported.configs" value="ecf.generic.server" />
 <entry key="org.eclipse.ecf.containerFactoryArgs" value="ecftcp://127.0.0.1:3787/server" />
            <entry key="org.eclipse.ecf.containerFactoryArgs" value="ecftcp://127.0.0.1:3787/server" />
 </osgi:service-properties>
        </osgi:service-properties>
 <bean class="com.dw.clac.service.impl.CalcServiceImpl" />
        <bean class="com.dw.clac.service.impl.CalcServiceImpl" />
 </osgi:service>
    </osgi:service>
 
    
 </beans>
</beans>
6.1 src/com.dw.calc.client.CalcServiceConsumer.java package com.dw.calc.client;
package com.dw.calc.client;

 import com.dw.calc.service.ICalcService;
import com.dw.calc.service.ICalcService;


 public class CalcServiceConsumer
public class CalcServiceConsumer  {
{

 ICalcService calcService;
    ICalcService calcService;


 public void setCalcService(ICalcService calcService)
    public void setCalcService(ICalcService calcService)  {
{
 this.calcService = calcService;
        this.calcService = calcService;
 }
    }


 public void start()
    public void start()  {
{
 System.out.println("2+3=" + calcService.plus(2, 3));
        System.out.println("2+3=" + calcService.plus(2, 3));
 }
    }

 }
} Manifest-Version: 1.0
Manifest-Version: 1.0
 Bundle-Version: 1.0.0
Bundle-Version: 1.0.0
 Bundle-Name: Client
Bundle-Name: Client
 Bundle-ManifestVersion: 2
Bundle-ManifestVersion: 2
 Bundle-SymbolicName: com.dw.calc.client
Bundle-SymbolicName: com.dw.calc.client
 Import-Package: com.dw.calc.service,
Import-Package: com.dw.calc.service,
 org.eclipse.core.runtime;version="[3.4.0,3.4.0]",
 org.eclipse.core.runtime;version="[3.4.0,3.4.0]",
 org.eclipse.ecf.core;version="[3.0.0,3.0.0]",
 org.eclipse.ecf.core;version="[3.0.0,3.0.0]",
 org.eclipse.ecf.springframework,
 org.eclipse.ecf.springframework,
 org.eclipse.ecf.springframework.identity,
 org.eclipse.ecf.springframework.identity,
 org.eclipse.equinox.app;version="[1.1.0,1.1.0]"
 org.eclipse.equinox.app;version="[1.1.0,1.1.0]"
 Import-Bundle: org.eclipse.ecf.provider;version="[4.2.100.v20120610-1946,4.2.100.v20120610-1946]"
Import-Bundle: org.eclipse.ecf.provider;version="[4.2.100.v20120610-1946,4.2.100.v20120610-1946]" <?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
    xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context.xsd"
        http://www.springframework.org/schema/context/spring-context.xsd"
 default-autowire="byName">
    default-autowire="byName">

 <bean class="com.dw.calc.client.CalcServiceConsumer" init-method="start">
    <bean class="com.dw.calc.client.CalcServiceConsumer" init-method="start">
 <property name="calcService" ref="calcServiceRef" />
        <property name="calcService" ref="calcServiceRef" />
 </bean>
    </bean>

 </beans>
</beans> <?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
<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"
    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
    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">
                      http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">

 <bean class="org.eclipse.ecf.springframework.ConsumerContainerFactoryBean">
    <bean class="org.eclipse.ecf.springframework.ConsumerContainerFactoryBean">
 <property name="containerType" value="ecf.generic.client" />
        <property name="containerType" value="ecf.generic.client" />
 </bean>
    </bean>
 
    
 <osgi:reference id="calcServiceRef" interface="com.dw.calc.service.ICalcService"
    <osgi:reference id="calcServiceRef" interface="com.dw.calc.service.ICalcService"
 timeout="1000" cardinality=
        timeout="1000" cardinality="0..1" filter="(org.eclipse.ecf.containerFactoryArgs=ecftcp://127.0.0.1:3787/server)" />
 
    
 </beans>
</beans>