卡拉夫的JNDI问题

时间:2015-06-17 12:27:54

标签: java osgi jndi karaf

我有两个捆绑包我想使用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,

提前致谢。

0 个答案:

没有答案