Access EJB 3.0 in JBoss 5, from JBoss 4 – java.lang.ClassCastException

If you are in a process of migrating JBoss servers you may sometimes need to deploy an EAR in a newer server, while having othres in the older servers, and keep the integration between the apps. I faced this issue when migrating from JBoss 4.3 to JBoss 5, but you may face a similar issue when migrating different versions.

One problem that may arrive when an application in the older server (JBoss 4) tries to access an EJB in the newer (JBoss 5) is this exception when doing a lookup:
java.lang.ClassCastException: javax.naming.Reference cannot be cast to XXX
Being XXX the interface you want to lookup in the JBoss 5 server.

This problem occurs because the application is using by default the client libraries of the JBoss 4 server. To solve this problem, you need to add the client jar files of the JBoss 5 server to the application in JBoss 4.
In order to do this, you need to copy the jars from JBoss 5 jbossall-client.jar and all its dependencies (listed in the META-INF, excluding jnp-client.jar) inside the application EAR file in JBoss 4 (in the lib folder inside the EAR).

This is the full list of jar files that need to be copied from /jboss-as/client inside /lib:
common-annotations.jar
commons-beanutils.jar
commons-collections.jar
commons-digester.jar
commons-logging.jar
concurrent.jar
ejb3-persistence.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-core.jar
hibernate-validator.jar
jboss-aop-client.jar
jboss-appclient.jar
jboss-aspect-jdk50-client.jar
jboss-client.jar
jboss-common-core.jar
jboss-deployers-client-spi.jar
jboss-deployers-client.jar
jboss-deployers-core-spi.jar
jboss-deployers-core.jar
jboss-deployment.jar
jboss-ejb3-common-client.jar
jboss-ejb3-core-client.jar
jboss-ejb3-ext-api-impl.jar
jboss-ejb3-ext-api.jar
jboss-ejb3-proxy-clustered-client.jar
jboss-ejb3-proxy-impl-client.jar
jboss-ejb3-proxy-spi-client.jar
jboss-ejb3-security-client.jar
jboss-ha-client.jar
jboss-ha-legacy-client.jar
jboss-iiop-client.jar
jboss-integration.jar
jboss-j2se.jar
jboss-javaee.jar
jboss-jsr77-client.jar
jboss-logging-jdk.jar
jboss-logging-log4j.jar
jboss-logging-spi.jar
jboss-mdr.jar
jboss-messaging-client.jar
jboss-profileservice-client.jar
jboss-remoting.jar
jboss-security-spi.jar
jboss-serialization.jar
jboss-srp-client.jar
jboss-system-client.jar
jboss-system-jmx-client.jar
jbossall-client.jar
jbosscx-client.jar
jbossjts.jar
jbosssx-as-client.jar
jbosssx-client.jar
jmx-client.jar
jmx-invoker-adaptor-client.jar
jsf-facelets.jar
jsf-tlds.jar
jstl.jar
PagosWebFachada.jar
richfaces-api-3.2.1.GA.jar
richfaces-impl-3.2.1.GA.jar
richfaces-ui-3.2.1.GA.jar
slf4j-api.jar
slf4j-jboss-logging.jar
standard.jar
xmlsec.jar

NOTE: If you fail to copy this list and add also the jnp-client.jar you will get this error when deploying the application:
java.lang.IncompatibleClassChangeError: Class org.jnp.server.NamingServer does not implement the requested interface org.jnp.interfaces.Naming

Advertisements