1 Reply Latest reply on Jun 22, 2004 5:31 AM by rverlind

    Strange JNDI problem

    rverlind

      I have a java client that uses JNDI to look up the HomeRemote interface for an EJB.
      When I use a jndi.properties file in the CLASSPATH this client does work without a hitch, but when I try to hard code the IntialContext settings into the application I get the following error :
      javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial



      This is the code I use to initalise the environment :
      When using the jndi.properties file :

      static public Context getInitialContext()
       throws NamingException {
       return new InitialContext();
       }


      When trying to hard code the thing :
      static public Context getInitialContext()
       throws NamingException {
       // Hard code the intialisation of the context parameters : DOESN'T WORK!!!
       Hashtable inEnv = new Hashtable();
       final String initialContextFactory = "org.jnp.interfaces.NamingContextFactory";
       final String initialURLPKGPrefixes = "org.jboss.naming:org.jnp.interfaces";
       final String initialProviderURL = "134.184.65.61";
      
       inEnv.put(Context.INITIAL_CONTEXT_FACTORY,initialContextFactory);
       inEnv.put(Context.PROVIDER_URL,initialProviderURL);
       inEnv.put(Context.URL_PKG_PREFIXES, initialURLPKGPrefixes);
      
       Context initialContext = new InitialContext(inEnv);
      
       return initialContext;
       }
      



      If I get the properties out of the Context (using initialContext.getEnvironment()) to look if they differ I get the same results for both :
      [java] * java.naming.factory.initial org.jnp.interfaces.NamingContextFactory
      [java] * java.naming.provider.url 134.184.65.61
      [java] * java.naming.factory.url.pkgs org.jboss.naming:org.jnp.interfaces



      I have absolutely no idea why it does work with the jndi.properties file and not the with hard coded settings. If anybody can give me an idea where to look, please ...

      regards,
      Ruben


        • 1. Re: Strange JNDI problem
          rverlind

          The intialisation of the JNDI from within the Eclipse plugin is working now using some ClassLoader changing :

           ClassLoader old = Thread.currentThread().getContextClassLoader();
           Thread.currentThread().setContextClassLoader(plugin.class.getClassLoader());
          
           // Initialise the JNDI environment
          
           Thread.currentThread().setContextClassLoader(old);
          



          Now the only problem remaining is the cache of the ServiceLocator that uses HomeHandles to cache as a reference to the EJBHome objects.
          Only, when trying to get an EJBHome object using
          homeHandle.getEJBHome()

          the same error occurs :
          javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
          vub.starlab.ds.bdelegate.EJB.BDelegateExceptionEJB: Service Locator Exception in OntoBaseDelegate




          Ruben