Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

EJB JNDI Exception

  • 06-01-2003 03:59PM
    #1
    Registered Users, Registered Users 2 Posts: 6,265 ✭✭✭


    Hi,

    I'm new to EJB and am currently writing my first bean, using the Sun Reference Implementation J2EE Server and deployment tool. I'm using examples provided in chapter 2 of the Wrox book "Professional EJB" to get me started.

    I have successfully written, compiled and deployed the application on the server, and now wish to test it using the example Java Client in the book. My Bean name is Salary, and is registered in the JNDI Server as Salary too, to keep things simple.

    The client code is as follows:

    try {
    InitialContext ctx = new InitialContext();
    Object objRef = ctx.lookup("Salary");

    SalaryHome home = (SalaryHome
    javax.rmi.PortableRemoteObject.narrow(
    objRef, SalaryHome.class);

    Salary bean = home.create();

    System.out.println("Monthly net salary: " +
    bean.calculateSalary(28000, 2, 500));

    } catch (javax.naming.NamingException ne) {
    System.out.println("Naming Exception caught: " + ne);
    } catch (javax.ejb.CreateException ce) {
    System.out.println("Create Exception caught: " + ce);
    } catch (java.rmi.RemoteException re) {
    System.out.println("Remote Exception caught: " + re);
    }

    When I attempt to run my client (which is one the same machine as the J2ee server) I get the following JNDI error:

    C:\ProEJB\Chapter2\code>java SalaryClient
    Naming Exception caught: javax.naming.NameNotFoundException: Salary not found

    Since I have copied the example code exactly, I can only assume it's a problem with my JNDI Server configuration. Can anyone help????


Comments

  • Registered Users, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭lynchie


    AFAIK, If your using the sun J2EE Server, all beans are bound to the following context within the JNDI tree java:comp/env/ejb/

    Thus your code should be
    Object objRef = ctx.lookup("java:comp/env/ejb/Salary");

    Check out
    the J2EE Tutorial for more info.


Advertisement