The problem is in your client. It should be:
NewSessionBeanRemote testEJB = (NewSessionBeanRemote)
ctx.lookup("ru.NewSessionBeanRemote");
The lookup doesn't return the bean.
The bean lives in the server. The lookup method returns an instance
(stub) that implements your interface and transparently delegates your
business method invocations to the actual bean instance in the server.
On 18/02/2010 19:33, glassfish_at_javadesktop.org wrote:
> have error, why ?:
> [i]Feb 18, 2010 12:56:13 PM com.sun.enterprise.transaction.JavaEETransactionManagerSimplified initDelegates
> INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
> Exception in thread "main" java.lang.ClassCastException: [b]ru._NewSessionBeanRemote_Wrapper cannot be cast to ru.NewSessionBean[/b]
> at ejb_client.Main.main(Main.java:31)[/i]
>
>
> [b]ejb server:[/b]
>
> NewSessionBeanRemote.java:
>
> [i]package ru;
> import javax.ejb.Remote;
>
> @Remote
> public interface NewSessionBeanRemote {
>
> String businessMethod(String parameter);
>
> }
> [/i]
>
> NewSessionBean.java:
>
> [i]package ru;
>
> import javax.ejb.Remote;
> import javax.ejb.Stateless;
>
> @Stateless
>
> public class NewSessionBean implements NewSessionBeanRemote {
>
> public String businessMethod(String parameter) {
> return "Hello EJB World";
> }
> }[/i]
>
>
> [b]client:[/b]
>
> [i]public class Main {
> public static void main(String[] args) {
> try {
> InitialContext ctx = new InitialContext();
> NewSessionBean testEJB = (NewSessionBean) ctx.lookup("ru.NewSessionBeanRemote");
> System.out.println(testEJB.businessMethod(null));
> } catch (NamingException nex) {
> nex.printStackTrace();
> }
> }
> }[/i]
>
> In classpath: gf-client.jar
> [Message sent by forum member 'technomen' (tomskiy_at_gmail.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=387338