public class MyModule implements BundleActivator { public void start(BundleContext context) throws Exception { System.out.println("MyModule started!"); } public void stop(BundleContext context) throws Exception { System.out.println("MyModule stopped!"); } } Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: com.example.mymodule Bundle-Version: 1.0.0 Import-Package: org.osgi.framework public static void main(String[] args) { FrameworkFactory factory = ServiceLoader.load(FrameworkFactory.class).iterator().next(); Framework framework = factory.newFramework(null); framework.start(); BundleContext context = framework.getBundleContext(); Bundle bundle = context.installBundle("file:/path/to/mymodule.jar"); bundle.start(); framework.stop(); framework.waitForStop(0); }


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