users@glassfish.java.net

Help looking up EJB in JNDI

From: Ryan de Laplante <ryan_at_ijws.com>
Date: Thu, 22 Feb 2007 11:54:25 -0500

Note: I posed this in nbusers then realized it's probably a better
question for here. Sorry for cross-posting.


Hi,

I've been struggling for 4 hours trying to do a simple JNDI lookup. I
have a stateless session bean (EJB 3.0) in an EJB Module project, a
Visual Web Project that uses JNDI to do a lookup, and the two projects
are packaged in a Enterprise Application project.

The EJB:

@Local
public interface MyDAOLocal {
...
}

@Stateless()
public class MyDAOBean
        implements MyDAOLocal {
...
}


The ServiceLocator in my web project:

public class ServiceLocator {
    private static InitialContext ic;

    static {
        try {
            ic = new InitialContext();
        } catch (NamingException ne) {
            throw new RuntimeException(ne);
        }
    }

    public static MyDAOLocal getMyDAOBean() {
        try {
            return (MyDAOLocal) ic.lookup("java:comp/ejb/MyDAOBean");
        } catch(NamingException ne) {
            ne.printStackTrace();
            throw new RuntimeException(ne);
        }
    }
}


I've tried all kinds of variations. I've tried looking up
"ejb/MyDAOBean", "MyDAOBean", "MyDAOBean/local",
"java:comp/ejb/MyDAOBean/local", etc...

I have also tried using the name attribute of the @Stateless annotation:

@Stateless(name="MyDAOBean")

Nothing seems to work. I always get a naming exception when trying to
look it up.

javax.naming.NameNotFoundException: No object bound to name
java:comp/env/ejb/MyDAOBean/local

When using the JNDI browser in the application server it doesn't show my
EJB. However I don't think my EJB would show up in the global JNDI. I
wish I could somehow browse the JNDI for my app to see what the darn
name is.

My web project has the EJB project listed as one of the libraries it
depends on to compile. It does not package the EJB project in the
WAR. Both the WAR and ejb project end up in the EAR.


I'm using NetBeans 5.5, Sun App Server 9.0 U1 P1, XP Pro.


Thanks,
Ryan