title: Class cast exception in Ejb lookup
body: <p>I have a simple multimodule maven project with a war ejb and ear</p>
  
  <p>When i am trying to access my ejb from a java pojo class using lookup it gives me class cast exception on wildfly it runs perfectly on jboss 7..</p>
  
  <p>I have checked almost all the links related to this post please do help if anyone know how to resolve this..Here is my sample code:</p>
  
  <p>My ejb interface:</p>
  
  <pre><code>package interfacejar;
  
  import javax.ejb.Local;
  
  
  public interface HelloWorldRemote {
         public String sayHello();       
         public void helloWait() ;  
  }
  </code></pre>
  
  <p>Session Bean</p>
  
  <pre><code>@Stateless
  public class HelloWorld implements Serializable, HelloWorldRemote {
  
      public String sayHello() {
          // TODO Auto-generated method stub
          return "hello";
      }
  
      public void helloWait(){
          // TODO Auto-generated method stub
      System.out.println("in ejb");   
      }
  
  
  
  }  
  </code></pre>
  
  <p>My War Interface:
  //As i am accessing ejb from pojo class which is in different module of my maven project so it requires to create interface here also in this module</p>
  
  <pre><code>package interfacejar;
  
  public interface HelloWorldRemote {
         public String sayHello();  
  
         public void helloWait() throws Exception;  
  }
  </code></pre>
  
  <p>My Java class</p>
  
  <pre><code>public class Testnew{
  
  
  
  
      public HelloWorldRemote getProps(){
          HelloWorldRemote ref=null;
           try {
          Properties props = new Properties();
          props.setProperty("java.naming.factory.initial","org.jboss.as.naming.InitialContextFactory");
          props.setProperty("java.naming.provider.url", "localhost");
          props.setProperty("jboss.naming.client.ejb.context", "true");
          props.setProperty("java.naming.factory.url.pkgs", "org.jboss.ejb.client.naming");
  
  
  
              Context context = new InitialContext(props);
  
              Object obj =    context.lookup("java:global/MyEarFile/testejb-0.0.1-SNAPSHOT/HelloWorld!interfacejar.HelloWorldRemote");
  
               ref=(HelloWorldRemote) obj;
  
          } catch (NamingException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
           return ref;
  
      }
  
  
  
  
          public void getRemote(){
              HelloWorldRemote ref=null;
              try {
                  ref=getProps();
  
                  ref.helloWait();
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
              }
  
  }
  </code></pre>
  
  <p>Servlet that calls this class</p>
  
  <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
  
      this.processRequest(request, response);
  
  }
  
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      this.processRequest(request, response);
  }
  //java:global/MyEarFile/testejb-0.0.1-SNAPSHOT/HelloWorld!interfacejar.HelloWorldRemote*
  /*@Resource(mappedName = "java:global/MyEarFile/tstwar-0.0.1-SNAPSHOT/HelloWorld!interfacejar.HelloWorldRemote")
  private HelloWorldRemote helloWorldRemote;*/
  
  protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      System.out.println("in servlet");
  
      Testnew testnew = new Testnew();
      testnew.getRemote();
  
  
  }
  </code></pre>
  
  <p>This is the error that i got</p>
  
  <pre><code>21:06:49,205 ERROR [stderr] (default task-3) java.lang.ClassCastException: interfacejar.HelloWorldRemote$$$view4 cannot be cast to interfacejar.HelloWorldRemote
  
  21:06:49,205 ERROR [stderr] (default task-3)    at com.test.Testnew.getProps(Testnew.java:43)
  
  21:06:49,205 ERROR [stderr] (default task-3)    at com.test.Testnew.getRemote(Testnew.java:59)
  </code></pre>