Forums Register Login

problem in deploying ejb3 app in jboss server

+Pie Number of slices to send: Send
Hello All!

I'm trying to develop a sample application using EJB3.

application has been deployed successfully...no problem with that.

But, when i try to call bean from my client code im getting following exception.


Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.kalki.session.MyBeanRemote
at com.kalki.session.MyBeanclient.main(MyBeanclient.java:28)


Here's is my complete code.

Super interface--->IMyBean

package com.kalki.session;

import java.io.Serializable;

public interface IMyBean extends Serializable{

public void show();


}

---------------------------------
Remote Interface----->>MyBeanRemote

package com.kalki.session;

import javax.ejb.Remote;

@Remote
public interface MyBeanRemote extends IMyBean{

}

---------------------------------------
Local Interface--->MyBeanLocal

package com.kalki.session;

import javax.ejb.Local;

@Local
public interface MyBeanLocal extends IMyBean{

}

--------------------------------------------
Session Bean---MyBean

package com.kalki.session;

import javax.ejb.Stateless;

@Stateless
public class MyBean implements MyBeanLocal, MyBeanRemote {



public void show()
{
System.out.println("Hi how are you");
}


}

----------------------------------------------
Client Class---->MyBeanclient

package com.kalki.session;

import java.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class MyBeanclient {

/**
* @param args
*/
public static void main(String[] args) {
try {




Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","=org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url","localhost:1099");
Context context;

context = new InitialContext(properties);
MyBeanRemote bean = (MyBeanRemote)context .lookup("MyBean/remote");
bean.show();

} catch (NamingException e) {
e.printStackTrace();
}

}

}

I googled for solution but it is of no help.

Please help me.

Thanks in advance,
Anil
+Pie Number of slices to send: Send
Which version of JBoss AS? And do you have the jbossall-client.jar (and the jars it references in it's MANIFEST.MF) in the client classpath?
+Pie Number of slices to send: Send
Hi jaikiran,

I am using Myeclipse IDE, im deploying the app in jboss-5.0.1.GA and i have added jbossall-client.jar to the build path.
As i said in my previous post that the app is getting deployed but when i run the client program im getting the exception.

Am i missing to add any other jar files?? Can you please list out the jars i should add to build path.

Thanks in advance,
Anil

+Pie Number of slices to send: Send
How do you run your client? From the IDE? I usually stay away from IDEs for building/running my apps, so i won't be able to help much around that.

Can you please list out the jars i should add to build path.



The client classpath should have the jbossall-client.jar and the other jars that are listed in the MANIFEST.MF of the jbossall-client.jar.
+Pie Number of slices to send: Send
you are wrong at this point:
context = new InitialContext(properties);
MyBeanRemote bean = (MyBeanRemote)context .lookup("MyBean/remote");
bean.show();


it should be:


context = new InitialContext(properties);
Object bean = (Object)context .lookup("MyBean/remote");
MyBeanRemote remoteBean=(MyBeanRemote)PortableRemoteObject.narrow(bean,MyBeanRemote.class)
bean.show();

+Pie Number of slices to send: Send
 

pankaj vijay wrote:you are wrong at this point:
context = new InitialContext(properties);
MyBeanRemote bean = (MyBeanRemote)context .lookup("MyBean/remote");
bean.show();


it should be:


context = new InitialContext(properties);
Object bean = (Object)context .lookup("MyBean/remote");
MyBeanRemote remoteBean=(MyBeanRemote)PortableRemoteObject.narrow(bean,MyBeanRemote.class)
bean.show();



The PortableRemoteObject.narrow is actually not required in EJB3. What Anil posted should work after he fixes the client classpath.
+Pie Number of slices to send: Send
 

The PortableRemoteObject.narrow is actually not required in EJB3. What Anil posted should work after he fixes the client classpath.



Yes it is not mandatory but if you will not use it... then probably it will not work on RMI.
+Pie Number of slices to send: Send
Its working fine now. Error was because of a jar file i missed to add in classpath.

Thank you,
Anil
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3098 times.
Similar Threads
whats wrong with this client ?
EJB 3.0 client error
EJB3 client error
Help EJB3
Interceptor and Exceptions
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:28:47.