Saturday, July 4, 2015

ClassCastException on remote EJB call between EARs in Websphere 8.5

We have 2 EARs running on the same Websphere 8.5 Application Server. Each EAR is running in its own classloader. We have a service that initiates a remote EJB call to another service exists in another EAR. Stubs are being generated automatically on startup since WAS 7.
One of our teams tried to perform some clean up and reorder to their legacy classpath.
Right after this classpath clean up, we were trying to initiate a remote EJB call, but for some reason it thrown the following exception:
"...ClassCastException...unable to load ..._Stub..."
We didnt understand why this exception came up? why ClassCastException?
We realized that our Remote interfaces were not identical between the EARs and that there were missing classes in classpath. So whenever you have such an architecture (if you are still using EJBs while calling your legacy systems :)), you should make sure that your remote interfaces are identical and you dont have any missing classes in the classpath of the calling EAR.