我有两个捆绑包我想使用JNDI
从捆绑包2访问bundle1,
如果我使用命令JNDI
绑定jndi:bind(serviceId, name binds a JNDI name)
,如果我将关闭将要关闭的karaf控制台,
然后我想用JNDI
使用持久OSGI
然后我创建了bundle1 as
bundle1 -
public void start(BundleContext bundleContext) throws Exception
{
try {
String karaf_home=System.getenv("KARAF_HOME");
bundleContext.registerService(IMyFramework.class.getName(), MyFrameworkFactory.initFramework("myprop.properties"), null);
Context cotx = new InitialContext();
// Runnable r = (Runnable) cotx.lookup("osgi:service/com.java.mytest.IMyFramework");
cotx.lookup("osgi:service/com.java.mytest.IMyFramework");
}
catch (Exception e) {
e.printStackTrace();
}
}
bundle2中 -
public void start(BundleContext context) throws Exception {
BundleContext bundleContext = FrameworkUtil.getBundle(ct.lookup("service/com.java.mytest.IMyFramework").getClass()).getBundleContext();
ServiceReference<?> serviceReference = bundleContext.getServiceReference(IPortFramework.class.getName());
Object serviceName = bundleContext.getService(serviceReference);
framework = (PortFramework) serviceName;
}
但无法访问, 请建议正确的方法或建议样本解决方案,我可以永久地为我的bundle1创建JNDI,
提前致谢。