EJB3 Remote JNDI lookup - javax.naming.Reference cannot be cast to <Remote Interface>

Standalone Client
From a standalone client, when I was doing a remote JNDI lookup for a EJB3 remote bean, I was getting the following exception:

Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference cannot be cast to sample.SampleRemote
at sample.Client.main(Client.java:14)


Sample bean was deployed in jboss-5.1.0.GA in a remote machine and I was running the client from my local machine. Initially I was suspecting the JNDI name I was using to do the lookup(JBoss' default remote jndi: <ejb-name>/remote) but after a few hours of research, I realized the issue is with the class loader.
The client was referring client classes of JBoss 5.0.1.GA which are not compatible with JBoss client classes in 5.1.0.GA.

So, I gave class path reference to 5.1.0.GA for my client and the lookup went fine!

Web Client
You may get a ClassCastException while trying to lookup/cast your EJB3 bean, the reason is described here.

http://community.jboss.org/wiki/ClassCastExceptions

Comments

  1. You can not even imagine how much your post helped me .
    Thank you very much.

    ReplyDelete
  2. @Anonymous, good to know that my blog saved your time! Thanks for posting comments.

    ReplyDelete
  3. This post worked for me too...

    Thank Sunil.

    - Amit

    ReplyDelete
  4. This helped me ...thanks

    ReplyDelete

Post a Comment

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to our feed and get articles like this delivered automatically to your feed reader? Like our Facebook Page.

Popular posts from this blog

Induction Cooker Showing an Error Code? Induction Cooker Error Codes Explained

HDFC Bank introduces Missed Call Service to know Account Balance

LICHFL - Generating Home Loan Statements Online