Pages

Monday, July 2, 2012

JBoss 6.0.0 java.lang.ClassCastException: javax.naming.Reference cannot be cast to

Error: JBoss 6.0.0 java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.xxx.xx.xxx.java

I am using maven3 to remotely run the JUnit based regression test on JBoss 6.0.0. While running a regression test for a Stateless Entity Persistence Bean on JBoss 6.0.0, I encountered the following error:
--
java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.pfmclient.glt.GLT
    at com.pfmclient.helper.EJBSupport.getGLT(EJBSupport.java:327)
--

Initially I thought that it means I don't have the ObjectFactory class on my client ClassPath. Thus throwing this error. However, I did have the Object Factory on my client classpath. I had spent hours then I found a solution that fixed the problem.

Fix:
Basically, I needed to include jbossall-client jar in the pom.xml as maven dependency for my project. However, the easiest and correct way to do this in JBoss 6.0.0 is to add the correct maven co-ordidnates for jboss-as-client pom. Add the following dependency to your pom.xml

<dependency>
        <groupId>org.jboss.jbossas</groupId>
        <artifactId>jboss-as-client</artifactId>
        <version>6.0.0.Final</version>
        <type>pom</type>
</dependency>

Please remember this is a fix for you if you use Maven 3 and JBoss 6.0.0

The above Maven artifact dependency will include all the necessary JBoss specific classes and even Java EE API classes required for JBoss 6.0.0.

Reference: 

 

1 comment:

  1. Great post it helped a lot after hours of figuring out what dependencies are missing.

    For jboss 6.1 just add the following:

    org.jboss.jbossas
    jboss-as-client
    6.1.0.Final
    pom
    test


    Great article.

    ReplyDelete