1 Reply Latest reply on Jul 10, 2005 6:34 PM by Darran Lofthouse

    JNDI problem

    ?ukasz Kaleta Newbie

      How use lookup method to find simple bean that return String "hello world".

      The folder structure within the Ejb-jar file looks as follows:
      META-INF/
      META-INF/MANIFEST.MF
      examples/
      examples/HelloBean.class
      examples/HelloHome.class
      examples/Hello.class
      examples/HelloLocal.class
      examples/HelloLocalHome.class
      META-INF/ejb-jar.xml

      J have write a class HelloClient

      public class HelloClient {
       public static void main(String[] args) throws Exception {
       Properties props = System.getProperties();
       Context ctx = new InitialContext(props);
       Object obj = ctx.lookup("HelloHome");
       HelloHome home = (HelloHome)
       javax.rmi.PortableRemoteObject.narrow(
       obj, HelloHome.class);
       Hello hello = home.create();
       System.out.println(hello.hello());
       hello.remove();
       }
      }


      but this
      Object obj = ctx.lookup("HelloHome");


      Exception in thread "main" 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
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at example.HelloClient.main(HelloClient.java:36)

        • 1. Re: JNDI problem
          Darran Lofthouse Master

          Instead of passing the system properties into the constructor just put a file called jndi.propertied on the classpath of the client app with the following properties: -

          java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
          java.naming.provider.url=jnp://127.0.0.1:1099
          java.naming.factory.url.pkgs=org.jboss.naming