1 Reply Latest reply on Jan 21, 2007 11:21 AM by Ryan McDonough

    EJB lookup after deploying to Jboss

    Richard Luo Newbie

      Hi everybody,

      I'm deploying a simple HelloWorld(Bean) to the jboss as following steps:
      1)Declare Remote statless session bean interface HelloWorld
      2)Construct a implementation class named HelloWorldBean to implement the Remote interface with annotation @Stateless, and there is a method sayHello
      3)Compile and make it jar files and then deploy it to jboss server
      4)Start jboss server
      5)Code the client class named TestHelloWorld

      A error occurred when I used following code:

       InitialContext ic = new InitialContext();
       HelloWorldBean hwBean = (HelloWorldBean) ic.lookup("HelloWorldBean/remote");
       ...
      


      But, if I used the following code it do not occur again:
       Hashtable ht = new Hashtable();
       ht.put(Context.PROVIDER_URL, "jnp://localhost:1099");
       ht.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       InitialContext ic = new InitialContext(ht);
       HelloWorldBean hwBean = (HelloWorldBean) ic.lookup("HelloWorldBean/remote");
      


      Would somebody help me? It confused me several days. In one word, I want to use Annotation but it seems not working correctly.
      Thanks in advance.

        • 1. Re: EJB lookup after deploying to Jboss
          Ryan McDonough Newbie

          It would be a bit more helpful if provided the stack trace of the error you are getting. But part of the problem is that you're assuming you'll be getting back you bean class, which you will not. With your HelloWorldBean, you should have a corresponding HelloWorld interface marked with an @Remotae annotation. Then your code should read:

          InitialContext ic = new InitialContext();
          HelloWorld hw = (HelloWorld) ic.lookup("HelloWorldBean/remote");
          


          That would be the proper way to write your code. Otherwise, you'll get a ClassCastException.

          Ryan-