<dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> <version>4.3.1</version> </dependency> groovy compile group: 'org.osgi', name: 'org.osgi.core', version: '4.3.1' import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; public class Activator implements BundleActivator { private static BundleContext context; static BundleContext getContext() { return context; } public void start(BundleContext bundleContext) throws Exception { Activator.context = bundleContext; ServiceReference<?> serviceReference = bundleContext.getServiceReference(YourServiceInterface.class); YourServiceInterface yourService = (YourServiceInterface) bundleContext.getService(serviceReference); yourService.yourMethod(); } public void stop(BundleContext bundleContext) throws Exception { Activator.context = null; } } public interface YourServiceInterface { void yourMethod(); } public class YourServiceImpl implements YourServiceInterface { public void yourMethod() { } } plaintext Bundle-SymbolicName: yourBundleName Bundle-Activator: com.example.Activator Export-Package: com.example Service-Component: OSGI-INF/yourService.xml


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