title: EJB Lookup Issue with WebSphere Application Server 6.1
body: <p>At first I want to tell that similar type of questions has been asked here but still I can't find the solution of my problem.</p>
  
  <p>I have a <strong>EJB 3</strong> Project (name = HelloWorldEJBProject). There I have created a stateless remote EJB (name = HelloWorldEJB). I have also created an remote interface there (name= HelloWorldEJBInterfaceRemote). After that I am creating a jar &amp; an ear of the project after compiling everything using ant. Then I deployed the EAR in the WebSphere Application Server 6.1.</p>
  
  <p>Next I have also created a stand alone java project (name = HelloWorldClient), put the jar of the HelloWorldEJBProject to this project build path. Now while I am doing the look up I am getting errors.</p>
  
  <p><strong>HelloWorldEJB.java:</strong></p>
  
  <pre><code>package com.staples.ejb;
  
  import com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote;
  import javax.ejb.Stateless;
  
  @Stateless
  public class HelloWorldEJB implements HelloWorldEJBInterfaceRemote {
  
  
      public HelloWorldEJB() {
      }
  
      public String helloWorld() {
  
          return "Hello World";
      }
  
  }
  </code></pre>
  
  <p><strong>Client.java (Inside HelloWorldClient project):</strong></p>
  
  <pre><code>package com.staples.client.processor;
  
  import com.staples.client.util.ApplicationUtil;
  import com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote;
  
  public class Client {
  
      static private HelloWorldEJBInterfaceRemote helloInterface = ApplicationUtil.getHelloEJBHandle();
  
      public static void main(String[] args) {
          System.out.println(helloInterface.helloWorld());
  
      }
  
  }
  </code></pre>
  
  <p><strong>ApplicationUtil.java (Inside HelloWorldClient project):</strong></p>
  
  <pre><code>import java.util.Hashtable;
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.rmi.PortableRemoteObject;
  
  import com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote;
  
  public class ApplicationUtil {
  
      public static Object getContext(){
          Object obj = null;
          Context context;
          try {
              Hashtable env = new Hashtable();
              env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
  
              env.put(Context.PROVIDER_URL,"corbaloc:iiop:localhost:2811");
  
              Context ctx = new InitialContext(env);
              obj = ctx.lookup("ejb/HelloEAR/Hello.jar/HelloWorldEJB#" + HelloWorldEJBInterfaceRemote.class.getName());
  
          } catch (NamingException e) {
              e.printStackTrace();
          }
          return obj;
      }
  
      public static HelloWorldEJBInterfaceRemote  getHelloEJBHandle()
      {   
  
          Object obj = getContext();
          HelloWorldEJBInterfaceRemote  helloInterface = (HelloWorldEJBInterfaceRemote) PortableRemoteObject.narrow(obj, HelloWorldEJBInterfaceRemote.class);
          //HelloWorldEJBInterfaceRemote  helloInterface = (HelloWorldEJBInterfaceRemote) obj;
          return  helloInterface;
  
  
  
      }
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>Exception in thread "P=141210:O=0:CT" java.lang.ClassCastException: Unable to load class: com.staples.ejb.interfaces._HelloWorldEJBInterfaceRemote_Stub
  at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:372)
  at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:156)
  at com.staples.client.util.ApplicationUtil.getHelloEJBHandle(ApplicationUtil.java:41)
  at com.staples.client.processor.Client.main(Client.java:14)
  </code></pre>
  
  <p>If I comment the following</p>
  
  <pre><code>HelloWorldEJBInterfaceRemote  helloInterface = (HelloWorldEJBInterfaceRemote) PortableRemoteObject.narrow(obj, HelloWorldEJBInterfaceRemote.class);
  </code></pre>
  
  <p>&amp; uncomment the following:</p>
  
  <pre><code>HelloWorldEJBInterfaceRemote  helloInterface = (HelloWorldEJBInterfaceRemote) obj;
  </code></pre>
  
  <p>then the following error comes:</p>
  
  <pre><code>Exception in thread "P=346416:O=0:CT" java.lang.ClassCastException: org.omg.stub.java.rmi._Remote_Stub incompatible with com.staples.ejb.interfaces.HelloWorldEJBInterfaceRemote
      at com.staples.client.util.ApplicationUtil.getHelloEJBHandle(ApplicationUtil.java:42)
      at com.staples.client.processor.Client.main(Client.java:14)
  </code></pre>
  
  <p>I am using <strong>EJB 3</strong> so I guess I dont need the PortableRemoteObject.narrow but without using that I get different error. I am not sure also what to write as a argument of context.lookup(). I am pretty new in EJB. Can anybody help me please? Thanks in advance. Thanks to MagicWand &amp; bkail to solve my port &amp; jndi problems.</p>