1 Reply Latest reply on Dec 19, 2005 9:23 AM by Dasari Prasad

    Help needed for an EJB (standalone) Application Client.

    v f Newbie


      I'm setting my first steps with EJB (using the JBoss Application Server) in Eclipse.
      Building a web-based application doesn't give any problems (there are plenty of good tutorials available) but making an (standalone) Application Client for my Beans gives a problem. Strangely enough not many tutorials handle that subject...

      The problem is I don't know how to do a Bean lookup from my Java Application.
      RandomBean just generates a random number.
      Here is some code I found, though this gives an error (see below):

      package randomclient;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.rmi.PortableRemoteObject;
      import random.RandomRemote;
      import random.RandomRemoteHome;
      public class RandomClient
      public static void main(String[] args) throws Exception
       Context initial = new InitialContext();
       Context env=(Context)initial.lookup("java:comp/env");
       Object obj=env.lookup("ejb/RandomBean");
       RandomRemoteHome home=(RandomRemoteHome)
       RandomRemote b=home.create();

      This is the error I'm getting:
      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(NamingManager.java:645)
       at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
       at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at Main.main(Main.java:15)

      It has to do with the Lookup() function (probably wrong values there) but I have absolutely no idea what to fill in there.

      Does someone have an idea please?

      Thanks a lot in advance!

        • 1. Re: Help needed for an EJB (standalone) Application Client.
          Dasari Prasad Newbie

          please do this to build the 'InitialContext" like

          public static InitialContext getInitialContext()
          Properties props=new Properties();
          InitialContext jndiCtx=null;
          jndiCtx=new InitialContext(props);
          catch(Exception ex)
          return jndiCtx;

          public static void main(String args[])
          System.out.println("\nBegin TimerSessClient...\n");

          InitialContext ctx=getInitialContext();
          Object obj=ctx.lookup("kattabomman");
          TimerSessHome home=(TimerSessHome)PortableRemoteObject.narrow(obj,TimerSessHome.class);
          System.out.println("Creating TimerSess Bean\n");
          TimerSess sess=home.create();........
          here TimerSess is remote interface of a sessionBean
          TimerSessHome is home interface
          you require client jars in class-path like jboss-client,jboss-j2ee,jnp-client etc

          Prasad DTR