users@glassfish.java.net

How to assign a jndi name to a ejb in glassfish 2.1?

From: <glassfish_at_javadesktop.org>
Date: Sun, 04 Oct 2009 19:55:22 PDT

I'm using ejb2.1 and trying to run it in glassfish 2.1 but the client couldn't find the relevant jndi name which I assign in sun-ejb-jar.xml under META-INF:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Application
Server 8.1 EJB 2.1//EN'
'http://www.sun.com/software/appserver/dtds/sun-ejb-jar_2_1-1.dtd'>
<sun-ejb-jar>
  <enterprise-beans>
    <ejb>
      <ejb-name>AdviceBean</ejb-name>
      <jndi-name>Advisor</jndi-name>
    </ejb>
  </enterprise-beans>
</sun-ejb-jar>

my ejb-jar.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
  <enterprise-beans>
      <session>
          <display-name>AdviceBean</display-name>
          <ejb-name>AdviceBean</ejb-name>
          <home>headfirst.AdviceHome</home>
          <remote>headfirst.Advice</remote>
          <ejb-class>headfirst.AdviceBean</ejb-class>
          <session-type>Stateless</session-type>
          <transaction-type>Bean</transaction-type>
          <security-identity>
              <description></description>
              <use-caller-identity></use-caller-identity>
          </security-identity>
      </session>
  </enterprise-beans>
</ejb-jar>

my client app:
import headfirst.AdviceHome;
import headfirst.Advice;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.ejb.CreateException;
import java.rmi.RemoteException;

public class AdviceClient {
    public static void main(String[] args) {
         new AdviceClient().go();
    }

    public void go(){

        try {
            Context ic=new InitialContext();
            System.out.println(ic.getNameInNamespace());
            Object o=ic.lookup("Advisor");
// Object o=ic.lookup("java:comp/Advisor");
            AdviceHome home=(AdviceHome) PortableRemoteObject.narrow(o,AdviceHome.class);

            Advice advisor=home.create();
            System.out.println(advisor.getAdvice());
        } catch (NamingException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (CreateException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (RemoteException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }

    }
}
[Message sent by forum member 'fxbird' (fxbird1978_at_163.com)]

http://forums.java.net/jive/thread.jspa?messageID=366756