5 Replies Latest reply on Nov 6, 2003 7:32 AM by darranl

    Basic doubt on Initial Context Factory

    mukesh_babu

      Hi,
      I am new to J2EE and Jboss. I have a small doubt in initial context. I have a bean deployed and from client i want to access it so i should do a JNDI look up.
      For this i am using the following code :
      Properties p = new Properties();
      p.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
      p.setProperty("java.naming.provider.url","jnp://" +m_serverHost + ":" + m_serverPort);
      tx= new InitialContext(p);
      home = ctx.lookup(beanName);

      The above code is working fine but i am able to look up the bean in following way also :
      Context ctx = new InitialContext();
      home = ctx.lookup(beanName);
      So my doubt is what is the advantage of setting the org.jnp.interfaces.NamingContextFactory and provider.url ?

      I will be thankful if some one can help in understanding the above doubt.
      I appreciate your help in this regard.
      Thankyou in advance.

      Regards,
      Vamsee.

        • 1. Re: Basic doubt on Initial Context Factory
          darranl

          Do you have any jndi.properties files in the classpath of the client, if you do the properties will be retrieved from there if you do not provide them yourself.

          I think some of the JBoss jar files contain a jndi.properties so depending on which jar files you have included is could be one of those.

          • 2. Re: Basic doubt on Initial Context Factory
            mukesh_babu

            Hi,
            Thankyou for your response.
            I dont have any properties file in classpath.
            Is there any advantage of specifying the properties while look up instead of using the default properties?

            Regards,
            Vamsee.

            • 3. Re: Basic doubt on Initial Context Factory
              darranl

              What is the full classpath that you are using for the client and which version of JBoss are you using?

              The connection details have got to be obtained from somewhere.

              • 4. Re: Basic doubt on Initial Context Factory
                mukesh_babu

                Hi,
                I am using Jboss 3.0.8 and in my classpath i have only run.jar. Actually i am doing a lookup of local home interface.
                Is it because i am doing a lookup of local home interface i am able to do it without specifying the properties?

                Thanks a lot for your support.
                Regards,
                Vamsee.

                • 5. Re: Basic doubt on Initial Context Factory
                  darranl

                  That makes sense now,

                  If you are running a client inside the same JBoss JVM do not provide any properties for the InitialContext and the JBoss defaults will be used.

                  If you are running a client outside of the JBoss JVM you will need to supply all the properties either as properties supplied to the InitialContext constructor or within a jndi.properties file on the classpath.