Glassfish v3 / JNDI entry cannot be found problems!
Posted
by REMP
on Stack Overflow
See other posts from Stack Overflow
or by REMP
Published on 2010-01-18T17:33:09Z
Indexed on
2010/03/18
8:01 UTC
Read the original article
Hit count: 791
I've been having problems trying to call an EJB's method from a Java Application Client. Here is the code.
EJB Remote Interface
package com.test;
import javax.ejb.Remote;
@Remote
public interface HelloBeanRemote {
public String sayHello();
}
EJB
package com.test;
import javax.ejb.Stateless;
@Stateless (name="HelloBeanExample" , mappedName="ejb/HelloBean")
public class HelloBean implements HelloBeanRemote {
@Override
public String sayHello(){
return "hola";
}
}
Main class (another project)
import com.test.HelloBeanRemote;
import javax.naming.Context;
import javax.naming.InitialContext;
public class Main {
public void runTest()throws Exception{
Context ctx = new InitialContext();
HelloBeanRemote bean = (HelloBeanRemote)ctx.lookup("java:global/Test/HelloBeanExample!com.test.HelloBeanRemote");
System.out.println(bean.sayHello());
}
public static void main(String[] args)throws Exception {
Main main = new Main();
main.runTest();
}
}
Well, what is my problem? JNDI entry for this EJB cannot be found!
java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at testdesktop.Main.runTest(Main.java:22)
at testdesktop.Main.main(Main.java:31) Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/Test/HelloBeanExample!com.test.HelloBeanRemote' in SerialContext [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext [Root exception is java.lang.NullPointerException]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at testdesktop.Main.runTest(Main.java:22)
at testdesktop.Main.main(Main.java:31) Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext [Root exception is java.lang.NullPointerException]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
... 3 more Caused by: java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
... 4 more Java Result: 1
I've trying with different JNDI entries but nothing works (I got this entries from NetBeans console):
INFO: Portable JNDI names for EJB HelloBeanExample : [java:global/Test/HelloBeanExample, java:global/Test/HelloBeanExample!com.test.HelloBeanRemote]
INFO: Glassfish-specific (Non-portable) JNDI names for EJB HelloBeanExample : [ejb/HelloBean, ejb/HelloBean#com.test.HelloBeanRemote]
So I tried with the following entries but I got the same exception :
- java:global/Test/HelloBeanExample
- java:global/Test/HelloBeanExample!com.test.HelloBeanRemote
- ejb/HelloBean
- ejb/HelloBean#com.test.HelloBeanRemote
I'm using Netbeans 6.8 and Glassfish v3!
© Stack Overflow or respective owner