Java Reference
In-Depth Information
Deployment will generate the code that the client needs to access the EJB. During
this process, you will give a name to the EJB. This name will be the name used to ac-
tually locate the EJB.
A CCESSING THE B EAN FROM THE C LIENT
The Java Naming and Directory Interface (JNDI) provides the facilities for finding
the remote server on which the EJB runs and for obtaining a reference to it. The
InitialContext is the starting point for this lookup process. The lookup() method
itself obtains the reference which is, in fact, a reference to the home interface. The
home interface is used for actually creating the EJB and obtaining an interface to ac-
cess its methods.
Context initial = new InitialContext();
java.lang.Object objref = initial.lookup("MyEJBName");
MyEJBHome home = (MyEJBHome)
PortableRemoteObject.narrow(objref,MyEJBHome .class);
MyEJBInterface myEJB = home.create();
// Now you can use the EJB.
String value = myEJB.getMyEJBValue();
E XERCISES
To do any exercises with EJBs, you will need a JEE-compliant application server. You
can download the JEE SDK from the Java Sun Web site. It contains everything you
will need to develop and test EJBs but is not a robust implementation that could be
used in a production environment. The Java Sun Web site at http://java.sun.com/
JEE/tutorial/index.html contains an excellent beginner's tutorial.
Following are high-level steps to code, deploy, and use a simple stateless Session-
Bean . The Java Sun tutorial provides details on how to do each of these steps.
1. Download the JEE SDK from Java Sun and install the software.
2. Code and compile the ConverterBean example found in the Getting Started
Section of the tutorial.
3. Code the ConverterClient application that accesses the ConverterBean .
4. Start the JEE Server.
5. Deploy the ConverterBean .
 
Search WWH ::




Custom Search