...
- Right-click the project
com.sample.blueprint.helloworld.api
and create a new Interface as shown in the figure.
- Name the Interface as HelloWorldService and package name as com.sample.blueprint.helloworld.api, then click Finish.
- Modify the code of
HelloWorldService
as follows.Code Block java java title HelloWorldService.javajava package com.sample.blueprint.helloworld.api; public interface HelloWorldService { public void hello(); public void startUp(); }
- Open
META-INF\MANIFEST.MF
and make surecom.sample.blueprint.helloworld.api
is listed under Exported packages.
...
- Right-click the project
com.sample.blueprint.helloworld.server
and create a new class as shown in the figure.
- Name the class as HelloWorldServiceImpl and the interface as HelloWorldService, then click Finish.
- Modify the code of
HelloWorldServiceImpl
as follows.Code Block java java title HelloWorldServiceImpl.javajava package com.sample.blueprint.helloworld.server; import com.sample.blueprint.helloworld.api.*; public class HelloWorldServiceImpl implements HelloWorldService { public void hello() { System.out.println("======>>> A message from the server: Hello World!"); } public void startUp() { System.out.println("======>>> Starting HelloWorld Server"); } }
- Right-click the project name and create a Blueprint file, then modify the xml file as follows. The blueprint file is placed under
OSGI-INF\blueprint
directory automatically.Code Block xml blueprint.xml <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <bean id="helloservice" class="com.sample.blueprint.helloworld.server.HelloWorldServiceImpl" init-method="startUp"> </bean> <service ref="helloservice" interface="com.sample.blueprint.helloworld.api.HelloWorldService"/> </blueprint>
- Modify
META-INF\MANIFEST.MF
and make surecom.sample.blueprint.helloworld.api
is listed under Import-Pakcage.
...
- Right-click the project
com.sample.blueprint.helloworld.client
and create a new class as shown in the figure.
- Name the class as HelloWorldClient and click Finish.
- Modify the code of
HelloWorldClient
as follows.Code Block java java title HelloWorldClient.javajava package com.sample.blueprint.helloworld.client; import com.sample.blueprint.helloworld.api.HelloWorldService; public class HelloWorldClient { HelloWorldService helloWorldService = null; public void startUp() { System.out .println("========>>>>Client HelloWorld: About to execute a method from the Hello World service"); helloWorldService.hello(); System.out .println("========>>>>Client HelloWorld: ... if you didn't just see a Hello World message something went wrong"); } public HelloWorldService getHelloWorldService() { return helloWorldService; } public void setHelloWorldService(HelloWorldService helloWorldService) { this.helloWorldService = helloWorldService; } }
- Right-click the project name and create a Blueprint file, then modify the xml file as follows. The xml is placed under
OSGI-INF\blueprint
directory automatically.Code Block xml blueprint.xml <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <reference id="helloservice" interface="com.sample.blueprint.helloworld.api.HelloWorldService" /> <bean id="helloclient" class="com.sample.blueprint.helloworld.client.HelloWorldClient" init-method="startUp"> <property name="helloWorldService" ref="helloservice" /> </bean> </blueprint>
- Modify
META-INF\MANIFEST.MF
and make surecom.sample.blueprint.helloworld.api
is listed under Import-Pakcage.
...