How to solve “javax.naming.Reference cannot be cast to javax.naming.Reference cannot be cast to ..”

This error means that the interface javax.naming.Reference cannot be resolved. It can happen when you are trying to lookup a component like an EJB or a Datasource from the JNDI. It is commonly caused by two reasons:
  1. You are missing some classes in client classpath (Verify that you have jbossall-client.jar in the classpath).
  2. You are using different JBoss runtimes between the client and the server. (For example the server uses JBoss 5.1.0 libraries and the client uses JBoss 5.0.0 or earlier)