users@glassfish.java.net

Re: Help looking up EJB in JNDI

From: Ryan de Laplante <ryan_at_ijws.com>
Date: Thu, 22 Feb 2007 13:36:09 -0500

Thanks very much. The problem was that I did not have an
<ejb-ref>...</ejb-ref> in my web.xml. I can't just do a JNDI lookup, I
need the ejb-ref declared. Since I'm using Visual Web Pack/JSF, I'm not
using servlets directly and can't use @EJB to inject the reference into
my POJO. I right clicked in my code window, Enterprise Resources -->
Call Enterprose Bean, and selected the EJB to have the ejb-ref added to
my web.xml. It now works correctly.


Ryan

Wouter van Reeven wrote:
> Hi Ryan,
>
>
> Have a look at
>
> https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html
>
> especially questions 1 and 3, and
>
> http://technology.amis.nl/blog/?p=1368
>
> FYI, if the Visual Web application is deployed on the same app server as the
> Enterprise module, preferable in the same Enterprise application though I am not
> sure if that's necessary, you may do something like
>
> @MyDAOLocal myDAOLocal;
> myDAOLocal.invokeThisReallyCoolMethod();
>
>
> HTH, Wouter van Reeven
>
> On Thu, Feb 22, 2007 at 11:54:25AM -0500, Ryan de Laplante wrote:
>
>> 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
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>>