JNDI issue in Karaf

134 views Asked by At

I have two one bundles I want to access bundle1 from bundle 2 using JNDI, if I am binding JNDI using command jndi:bind(serviceId, name binds a JNDI name), if I will close the karaf console that will go off, then I thought to use persistent JNDI using OSGI then I created 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;
  }

but its not accessible, Please suggest the right approach or suggest sample solution that how permanently I can create JNDI for my bundle1,

Thanks in advance.

0

There are 0 answers