Return-Path: Delivered-To: apmail-geronimo-user-archive@www.apache.org Received: (qmail 68546 invoked from network); 6 Aug 2006 20:11:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Aug 2006 20:11:46 -0000 Received: (qmail 11380 invoked by uid 500); 6 Aug 2006 20:11:40 -0000 Delivered-To: apmail-geronimo-user-archive@geronimo.apache.org Received: (qmail 11359 invoked by uid 500); 6 Aug 2006 20:11:40 -0000 Mailing-List: contact user-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: user@geronimo.apache.org List-Id: Delivered-To: mailing list user@geronimo.apache.org Received: (qmail 11348 invoked by uid 99); 6 Aug 2006 20:11:40 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 Aug 2006 13:11:40 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of ammulder@gmail.com designates 64.233.182.191 as permitted sender) Received: from [64.233.182.191] (HELO nf-out-0910.google.com) (64.233.182.191) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 Aug 2006 13:11:39 -0700 Received: by nf-out-0910.google.com with SMTP id l36so2056667nfa for ; Sun, 06 Aug 2006 13:11:18 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=pZlnRpnvLZryWuP+N29uxhWeV8c7PO23V+ciIWenjFEgm8SYFd/ke//fzUMWYali4298clHln8lqMbj377wCMfqQN6Ri7/E4eTJpsdoNhryRhpRgcyhwcB6Zww/LfbjP0mf4ADxxrllr2Sfgfp7oTh3a3wPSUgZ6tfJv3EGyrks= Received: by 10.78.200.3 with SMTP id x3mr2179876huf; Sun, 06 Aug 2006 13:11:17 -0700 (PDT) Received: by 10.78.196.5 with HTTP; Sun, 6 Aug 2006 13:11:17 -0700 (PDT) Message-ID: <74e15baa0608061311p5c0aa9f5x7b662a9e9fcc997e@mail.gmail.com> Date: Sun, 6 Aug 2006 16:11:17 -0400 From: "Aaron Mulder" Sender: ammulder@gmail.com To: user@geronimo.apache.org Subject: Re: NameNotFoundException with EJB created with Eclipse Geronimo plugin In-Reply-To: <9d6ee3e70608061250s7d9a88b1qaaa076d48868d98e@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <9d6ee3e70608061250s7d9a88b1qaaa076d48868d98e@mail.gmail.com> X-Google-Sender-Auth: be538316827ba68e X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N All right, this is just scratching the surface, but... In order for a web application to access an EJB, you need to add an "EJB Reference" to the web application for each EJB that the web application is going to use. The EJB reference puts the EJB in the web application's private JNDI space. There's one last wrinkle, which is that an EJB may have home & remote interfaces, localhome & local interface, or all 4. For a web application that's going to use EJBs, you'll want to use the localhome & local interfaces, because the performance is better (the local approach only works for clients in the same JVM as the EJB). I mention that because technically there's different syntax to create a remote EJB reference and a local EJB reference for the web application, and I'm only going to describe the local syntax here. Now, your Tiger EJB already has local home and local interfaces, so everything's fine on the EJB side. To set up the EJB reference, add a block to your web.xml like this: ... ejb/Tiger Session com.zoo.example.TigerLocalHome com.zoo.example.TigerLocal Tiger So long as your web application and the EJB are in the same EAR, this is all you need. If they were separated, you couldn't necessarily use the ejb-link element and you might need to add some information to geronimo-web.xml instead. In the block above, the ejb-ref-name controls where in JNDI the EJB will appear, the next three elements have to match the similar fields in the ejb-jar.xml for this EJB, and the ejb-link must match the ejb-name for that EJB in the ejb-jar.xml. The exact JNDI location the web app should use to access the EJB is "java:comp/env/" plus the value of the ejb-ref-name -- so in this case, it would be "java:comp/env/ejb/Tiger". Now, I'm not sure what your TigerUtil class does, but this is what the code would look like for a web application to use this EJB: Context ctx = new InitialContext(); TigerLocalHome home = (TigerLocalHome)ctx.lookup("java:comp/env/ejb/Tiger"); TigerLocal tiger = home.create(); The TigerUtil class probably hides some of this by declaring a constant for the JNDI location of the EJB, and so on. But you're calling the wrong method on it if it returns a TigerHome -- you want a method that returns a TigerLocalHome, as I mentioned above. If TigerUtil is a generated class and has a different JNDI location than java:comp/env/ejb/Tiger to look up the TigerLocalHome, then you can change the ejb-ref-name in your web.xml so the JNDI location will match whatever TigerUtil is using. Thanks, Aaron On 8/6/06, Four Sticks wrote: > Hi, > > I have eclipse 3.2, the Callisto version of WebTools, JDK 1.5 and the > Geronimo 1.1 plugin. I'm able to create and run serverlets and JSP's > just fine to Geronimo, but I'd like to learn about EJB's. > > I'm using this tutorial as a guide: > http://www.eclipse.org/webtools/community/tutorials/ejbtutorial/buildingejbs.html > > Following this tutorial, I created an EJB project named Zoo, a Web > project named ZooWeb and an EAR named ZooEAR. In the Zoo EJB project > is an EJB named TigerBean. The plugin created a ZooClient project. In > the Web project is a JSP page named Test.jsp which gets the EJB and > calls a method on it. > > It looked like everything created fine, but when I run the project on > the Geronimo server. The JSP page is failing on the following line of > java code: > > com.zoo.example.TigerHome home = com.zoo.example.TigerUtil.getHome(); > > with the following error: > > javax.naming.NameNotFoundException: Tiger > > My question is what do I need to do so the JSP page can find the EJB? > > Here is the web.xml file creatd by the plugin: > > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> > > ZooWeb > > index.html > > > > There is also a geronimo-web.xml file: > > > xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1" > xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1" > xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"> > > > default > ZooWeb > 1.0 > car > > > /ZooWeb > > > Do I need to add something to these two files? I'd appreciate any help > at all. I'm not to familiar with EJB's so I'm not sure what I need to > do so that the JSP page can find them. > > In the Zoo Ejb project the ejb-jar.xml file has the following: > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee > http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1"> > extension.]]> > Zoo > > > > > > > Tiger > > Tiger > > com.zoo.example.TigerHome > com.zoo.example.Tiger > com.zoo.example.TigerLocalHome > com.zoo.example.TigerLocal > com.zoo.example.TigerSession > Stateless > Container > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ZooClient.jar > > > > And there is also an openejb-jar.xml file in the EJB projcect with the > following: > > > xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1" > xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0" > xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1" > xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"> > > > default > Zoo > 1.0 > car > > > > > > Any help at all would be gratefully appreciated it. > > Thanks, > Gaston >