1 Reply Latest reply on May 12, 2002 10:25 PM by sgturner

    How to compile & run manually Interest example

    khdam

      Hi,

      I am trying to run the interest example manually but it fails. I got the context but the line:

      Object ref = jndiContext.lookup("interest/Interest");

      So I can't have the reference.
      The exception I have is :

      javax.naming.NoInitialContextException : Need to specify class name in environnement or system properties, or as a applet parameter, or in an application resource file : javax.naming.factory.initial

      I have included in the classpath all the client jars, and interest.jar

      I am using JBoss2.4.4 on Windows Me.

      Thanks a lot for your help!

        • 1. Re: How to compile & run manually Interest example
          sgturner

          I suggest that you read up on JNDI. If you do this:

          Context jndiContext = new InitialContext();
          Object ref = jndiContext.lookup("interest/Interest");

          then the InitialContext is trying to get init info from System.properties. Your exception makes clear that it can not find the info it needs. There are at least 2 ways to solve this. One is to pass the required info as system properties in the command line of your main. The other is to specify the info explicitly in the code:

          Properties props = new Properties();
          props.put (Context.PROVIDER_URL,
          "jnp://localhost:1099");
          props.put(Context.INITIAL_CONTEXT_FACTORY,
          "org.jnp.interfaces.NamingContextFactory");
          Context jndiContext = new InitialContext(props);
          Object ref = jndiContext.lookup("interest/Interest");

          Of course replace localhost above, with whatever is appropriate for your environment.

          This is an excellent book on JNDI:
          http://www.amazon.com/exec/obidos/ASIN/0201705028/qid=1021256685/sr=1-2/ref=sr_1_2/103-4964161-8897410