import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; ... public class MyActivator implements BundleActivator { private Context context; public void start(BundleContext bundleContext) throws Exception { context = new InitialContext(); bundleContext.registerService(Context.class.getName(), context, null); } public void stop(BundleContext bundleContext) throws Exception { ServiceRegistration<?> serviceRegistration = bundleContext.getServiceRegistration(Context.class.getName()); if (serviceRegistration != null) { serviceRegistration.unregister(); } } } import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; ... public class MyService { private Context context; public void bindString(String name, String value) throws NamingException { context = new InitialContext(); context.bind(name, value); } public String getString(String name) throws NamingException { context = new InitialContext(); return (String) context.lookup(name); } }


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