I was trying the first EJB example of the book "Mastering Enterprise
Java Beans". After building the bean and deploying it successfully I
had many problems making the client work. The client code is very
simple
public class Main {
public static void main(String[] args) throws Exception{
Context ctx=new InitialContext();
Hello hello=(Hello)ctx.lookup("HelloBean");
System.out.println(hello.hello());
}
}
But I found many problems using the lookup method. Using the full
"path" for the interface "examples.session.stateless.Hello", as
specified in the book, I got
Exception in thread "main" javax.naming.NameNotFoundException:
examples.session.stateless.Hello not bound
Otherwise, using the line
Hello hello=(Hello)ctx.lookup("HelloBean");
I got the error
Exception in thread "main" java.lang.ClassCastException:
org.jnp.interfaces.NamingContext cannot be cast to
examples.session.stateless.Hello
So I think I was grabbing the wrong object from JBoss. Looking on many
posts and web pages I found that using
Hello hello=(Hello)ctx.lookup("HelloBean/remote");
I can get the right object. Why? It's really difficult for me to
understand the way JNDI is naming my resources...can you give me
informations about that? It would be really appreciated...
Cold