Accessing Local Stateless EJB directly from a JSP


EJB programming & troubleshooting: Accessing Local Stateless EJB directly from a JSP

  1. Hi All,

    I am developing a simple application that displays some information from a stateless session bean in a JSP. The EJB is a local EJB and is packaged in a jar file. The jsp is packaged within a .war file. Both these together are packaged in a .ear file. I am running this on weblogic 7.0.

    The error I get is the following. The deployment descriptors I use are also pasted below. Any help would be appreciated.


    <Jan 14, 2004 11:22:42 AM CST> <Error> <HTTP> <101017> <[ServletContext(id=1257716,name=webapp.war,context-path=/admin)] Root cause of ServletException
    javax.naming.NameNotFoundException: Unable to resolve 'app/webapp/webapp.war/1257716/comp/env/ConfigAPIEJB' Resolved: 'app/webapp/webapp.war/1257716/comp/env' Unresolved:'ConfigAPIEJB' ; remaining name 'ConfigAPIEJB'
            at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(
            at weblogic.jndi.internal.BasicNamingNode.lookupHere(
            at weblogic.jndi.internal.BasicNamingNode.lookup(
            at weblogic.jndi.internal.BasicNamingNode.lookup(

    I) The .war files

    1. web.xml
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
       PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        <display-name>Team Project - Config</display-name>

    2. weblogic.xml
      <description> Config project text description </description>

    3. ConfigView.jsp (excerpt)

         Context localCtx= new InitialContext();
         cfgHome = (ConfigAPIHomeLocal) localCtx.lookup("java:comp/env/ConfigAPIEJB");

    II) The ejb deployment descriptors (inside sample.jar)

    1. ejb-jar.xml

    /local-home> <local>sample.ejb.cfg.ConfigAPILocal</local>

    2. weblogic-ejb-jar.xml


    III) Application (.ear) files

    1. application.xml
      <display-name>Config EAR</display-name>
      <description>Application to display ejb config</description>
  2. have you tried java:comp/env/ejb/<EJBNAME> ?
  3. Hello Stephen,

    Yes, I have tried to change the lookup in the jsp to "java:comp/env/ejb/ConfigAPIEJB".

    What I dont undertand is whether registering the EJB with the <jndi-name> element set to "ConfigAPIEJB" (in weblogic-ejb-jar.xml) automatically sets the ENC registery name to ejb/ConfigAPIEJB or do I have to try and change the element <jndi-name> also to "ejb/ConfigAPIEJB" (in weblogic-ejb-jar.xml)?

    I figured that as with the usual JNDI lookup, it would just put it into the base (=java:comp/env) + jndi-name (=ConfigAPIEJB). If this is the case, then I am kinda stuck understanding why the lookup fails.

  4. Hi!

    Try to add <ejb-link>sample.jar#ConfigAPIEJB</ejb-link> element right before the </ejb-local-ref> closing tag in your web.xml.
  5. Hi Alexey,

    Thank you for your suggestion.

    I tried adding that line and it doesnt appear to help. Is there something special that needs to be done since the .war and .jar files are packaged together in a .ear?

    To get things working, I changed the local bean to a remote bean and it works just fine. I would prefer to get the local bean working though :(

    Thanks again,
  6. Try also to replace <jndi-name>ConfigAPIEJB</jndi-name>
    with <local-jndi-name>ConfigAPIEJB</local-jndi-name> in your weblogic-ejb-jar.xml
  7. Hi Alexey,

    Thanks for your suggestions. I finally managed to get it working.

    The solution seems to be to remove the binding of jndi for the local ejb. So I modified my weblogic.xml by removing the <reference-descriptor>. Also added the <ejb-link> element in web.xml. I removed the binding of ejb to jndi (<local-jndi-name>) from the weblogic-ejb-jar.xml too. Finally I added a "Class-Path:" entry to the sample.jar in my webapp's Manifest file and everything looks ok now.