public interface HelloService { void sayHello(); } public class HelloServiceImpl implements HelloService { public void sayHello() { System.out.println("Hello from OSGi!"); } } maniyfest Bundle-ManifestVersion: 2 Bundle-SymbolicName: com.example.mybundle Bundle-Version: 1.0.0 Export-Package: com.example.mybundle Import-Package: org.osgi.framework Service-Component: OSGI-INF/mybundle.xml shell g! install file:/path/to/mybundle.jar g! start mybundle import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; public class ClientBundle { private BundleContext context; public void activate(BundleContext context) { this.context = context; ServiceReference<HelloService> reference = context.getServiceReference(HelloService.class); HelloService service = context.getService(reference); service.sayHello(); } }


上一篇:
下一篇:
切换中文