Hi,

Many times we fall into one issue when we try to invoke the EJBs which are deployed on JBoss Server but the EJB Client modules are deployed on any Non-JBoss server like Tomcat/WebLogic or WebSphere. So in this case we need a minimum set of Jars which we can place at the client side to invoke the EJBs which are running on JBoss.

JBoss also provides “$JBOSS_HOME/client/jbossall-client.jar” file which comtains a “META-INF/MANIFEST.MF” file entry to refer to all the other Jars which are present in the “$JBOSS_HOME/client” directory. But the problem with this Jar is this Jar actually doesnot contain any Classes rather it contains only the classpath reference of other JARs so this single JAR file is of no use. We will need to either place all the “$JBOSS_HOME/client/*.jar” inside the Jboss Client application (Which will unnecessarily increase the size of Client application) or We have to selectively find out the required Jars.

If the required Jars are not set properly at the Client side then usually we get the following kind of StackTrace of the exception while performing a lookup to the JBoss JNDI:

Caused by: java.lang.ClassCastException: javax.naming.Reference
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java: ...)

To avoid this kind of exceptions while lookup we must make sure that the Classpath of the client is set properly. It is better to have the following set og JARs at the client side to avoid these kind of exceptions to be thrown at the EJB invocation time.

If you don’t have JBoss installed on the Client Box then please Use the Jars mentioned in the following scripts for your EJB Client Application’s.

For Windows Operating System if you want to run EJB Client then please make sure that the following JARs are present in the Clients classpath Or you can also run the following BAT file to set the JBoss EJB Client classpath properly:

set JAVA_HOME=C:MyJDKsjdk160_05
set PATH=%JAVA_HOME%/bin;%PATH%

set CLIENT_JARS_DIR=E:/jboss-AS6/jboss-as/client
set CLASSPATH=
echo "CLASSPATH = $CLASSPATH"

set CLASSPATH=%CLIENT_JARS_DIR%/jboss-logging-spi.jar;%CLIENT_JARS_DIR%/jnp-client.jar;%CLIENT_JARS_DIR%/jboss-ejb3-proxy-impl-client.jar;%CLIENT_JARS_DIR%/jboss-ejb3-common-client.jar;;%CLIENT_JARS_DIR%/jboss-aspect-jdk50-client.jar;%CLIENT_JARS_DIR%/jboss-remoting.jar;%CLIENT_JARS_DIR%/jboss-aop-client.jar;%CLIENT_JARS_DIR%/jboss-common-core.jar;%CLIENT_JARS_DIR%/jboss-serialization.jar;%CLIENT_JARS_DIR%/jboss-ejb3-security-client.jar;%CLIENT_JARS_DIR%/jbosssx-client.jar;%CLIENT_JARS_DIR%/jboss-security-spi.jar;%CLIENT_JARS_DIR%/jboss-javaee.jar;%CLIENT_JARS_DIR%/ejb3-persistence.jar;%CLIENT_JARS_DIR%/jboss-ejb3-security-client.jar;%CLIENT_JARS_DIR%/jboss-ejb3-vfs-spi.jar;%CLIENT_JARS_DIR%/concurrent.jar;%CLIENT_JARS_DIR%/jboss-ejb3-proxy-spi-client.jar;%CLIENT_JARS_DIR%/jboss-ejb3-core-client.jar;%CLIENT_JARS_DIR%/jboss-integration.jar;.;

echo CLASSPATH=%CLASSPATH%

For Unix Based OS you can run the following Shell script to set the JBoss EJB Client classpath properly:

export JAVA_HOME=/home/testuser/MyJDKs/jdk160_05
export PATH=${JAVA_HOME}/bin:${PATH}:

CLIENT_JARS_DIR=/JBoss_All/jboss-AS6/jboss-as/client

export CLASSPATH=
echo "CLASSPATH = $CLASSPATH"

export CLASSPATH="${CLIENT_JARS_DIR}/jboss-logging-spi.jar:${CLIENT_JARS_DIR}/jnp-client.jar:${CLIENT_JARS_DIR}/jboss-ejb3-proxy-impl-client.jar:${CLIENT_JARS_DIR}/jboss-ejb3-common-client.jar::${CLIENT_JARS_DIR}/jboss-aspect-jdk50-client.jar:${CLIENT_JARS_DIR}/jboss-remoting.jar:${CLIENT_JARS_DIR}/jboss-aop-client.jar:${CLIENT_JARS_DIR}/jboss-common-core.jar:${CLIENT_JARS_DIR}/jboss-serialization.jar:${CLIENT_JARS_DIR}/jboss-ejb3-security-client.jar:${CLIENT_JARS_DIR}/jbosssx-client.jar:${CLIENT_JARS_DIR}/jboss-security-spi.jar:${CLIENT_JARS_DIR}/jboss-javaee.jar:${CLIENT_JARS_DIR}/ejb3-persistence.jar:${CLIENT_JARS_DIR}/jboss-ejb3-security-client.jar:${CLIENT_JARS_DIR}/jboss-ejb3-vfs-spi.jar:${CLIENT_JARS_DIR}/concurrent.jar:${CLIENT_JARS_DIR}/jboss-ejb3-proxy-spi-client.jar:${CLIENT_JARS_DIR}/jboss-ejb3-core-client.jar:${CLIENT_JARS_DIR}/jboss-integration.jar"

echo "CLASSPATH=$CLASSPATH"

.
.
Thanks
Middleware Magic

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.