I have tried to it with an OSGi Service but I don't know how to add the service in the project. Do you have an advice ?
With this example I have the OSGiDmHelloworldProvider and OSGiDmHelloworldConsumer : ( http://baptiste-wicht.com/posts/2010/07/osgi-hello-world-services.html <http://baptiste-wicht.com/posts/2010/07/osgi-hello-world-services.html> ) –------------------------------------------------------------------------------------------------- Project OSGiDmHelloworldProvider –------------------------------------------------------------------------------------------------- –----------------------------------------------------------- HellloWorldService.java –----------------------------------------------------------- package com.bw.osgi.provider.able; public interface HelloWorldService { void hello(); } –----------------------------------------------------------- HelloWorldSServiceImpl.java –----------------------------------------------------------- package com.bw.osgi.provider.impl; import com.bw.osgi.provider.able.HelloWorldService; public class HelloWorldServiceImpl implements HelloWorldService { @Override public void hello(){ System.out.println("buenos dia !"); } } –----------------------------------------------------------- ProviderActivator.java –----------------------------------------------------------- package com.bw.osgi.provider; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import com.bw.osgi.provider.able.HelloWorldService; import com.bw.osgi.provider.impl.HelloWorldServiceImpl; public class ProviderActivator implements BundleActivator { private ServiceRegistration registration; @Override public void start(BundleContext bundleContext) throws Exception { registration = bundleContext.registerService( HelloWorldService.class.getName(), new HelloWorldServiceImpl(), null); } @Override public void stop(BundleContext bundleContext) throws Exception { registration.unregister(); } } –----------------------------------------------------------- MANIFIEST.MF –----------------------------------------------------------- Manifest-Version: 1.0 Bnd-LastModified: 1403515786494 Build-Jdk: 1.7.0_25 Built-By: florian Bundle-Activator: com.bw.osgi.provider.ProviderActivator Bundle-ManifestVersion: 2 Bundle-Name: OSGiDmHelloWorldProvider Bundle-SymbolicName: OSGiDmHelloWorldProvider Bundle-Vendor: Baptiste Wicht Bundle-Version: 1.0.0 Created-By: Apache Maven Bundle Plugin Export-Package: com.bw.osgi.provider.able;version="1.0.0" Import-Package: com.bw.osgi.provider.able,org.osgi.framework;version="[1 .3,2)" Tool: Bnd-2.1.0.20130426-122213 –----------------------------------------------------------- OSGiDmHelloWorldProvider.iml –----------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/target/classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" /> <content url="file://$MODULE_DIR$"> <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> <excludeFolder url="file://$MODULE_DIR$/target" /> </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="library" exported="" name="Maven: org.apache.felix:org.osgi.core:1.0.0" level="project" /> </component> </module> –----------------------------------------------------------- pom.xml –----------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>OSGiDmHelloWorldProvider</groupId> <artifactId>OSGiDmHelloWorldProvider</artifactId> <version>1.0</version> <packaging>bundle</packaging> <dependencies> <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.osgi.core</artifactId> <version>1.0.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> <Bundle-SymbolicName>OSGiDmHelloWorldProvider</Bundle-SymbolicName> <Export-Package>com.bw.osgi.provider.able</Export-Package> <Bundle-Activator>com.bw.osgi.provider.ProviderActivator</Bundle-Activator> <Bundle-Vendor>Baptiste Wicht</Bundle-Vendor> </instructions> </configuration> </plugin> </plugins> </build> </project> –-------------------------------------------------------------------------------------------------- Project OSGiDmHelloworldConumer –--------------------------------------------------------------------------------------------------- –----------------------------------------------------------- HelloWorldActivator.java –----------------------------------------------------------- package com.bw.osgi.consumer; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import com.bw.osgi.provider.able.HelloWorldService; public class HelloWorldActivator implements BundleActivator { private HelloWorldConsumer consumer; @Override public void start(BundleContext bundleContext) throws Exception { ServiceReference reference = bundleContext.getServiceReference(HelloWorldService.class.getName()); consumer = new HelloWorldConsumer((HelloWorldService) bundleContext.getService(reference)); consumer.startTimer(); } @Override public void stop(BundleContext bundleContext) throws Exception { consumer.stopTimer(); } } –----------------------------------------------------------- HelloWorldConsumer.java –----------------------------------------------------------- package com.bw.osgi.consumer; import javax.swing.Timer; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import com.bw.osgi.provider.able.HelloWorldService; public class HelloWorldConsumer implements ActionListener { private final HelloWorldService service; private final Timer timer; public HelloWorldConsumer(HelloWorldService service) { super(); this.service = service; timer = new Timer(1000, this); } public void startTimer(){ timer.start(); } public void stopTimer() { timer.stop(); } @Override public void actionPerformed(ActionEvent e) { service.hello(); } } –----------------------------------------------------------- OSGiDmHelloWorldConsumer.iml –----------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false"> <output url="file://$MODULE_DIR$/target/classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" /> <content url="file://$MODULE_DIR$"> <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> <excludeFolder url="file://$MODULE_DIR$/target" /> </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="library" exported="" name="Maven: org.apache.felix:org.osgi.core:1.0.0" level="project" /> <orderEntry type="module" module-name="OSGiDmHelloWorldProvider" exported="" /> </component> </module> –----------------------------------------------------------- pom.xml –----------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>OSGiDmHelloWorldConsumer</groupId> <artifactId>OSGiDmHelloWorldConsumer</artifactId> <version>1.0</version> <packaging>bundle</packaging> <dependencies> <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.osgi.core</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>OSGiDmHelloWorldProvider</groupId> <artifactId>OSGiDmHelloWorldProvider</artifactId> <version>1.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> <Bundle-SymbolicName>OSGiDmHelloWorldConsumer</Bundle-SymbolicName> <Bundle-Activator>com.bw.osgi.consumer.HelloWorldActivator</Bundle-Activator> <Bundle-Vendor>Baptiste Wicht</Bundle-Vendor> </instructions> </configuration> </plugin> </plugins> </build> </project> -- View this message in context: http://karaf.922171.n3.nabble.com/Karaf-Tutorial-Part-4-CXF-Services-in-OSGi-How-to-use-a-new-service-tp4033785p4033787.html Sent from the Karaf - User mailing list archive at Nabble.com.