Consider Lightweight Directory Access Protocol (LDAP) stateless
session bean. Creating an EJB and using it consists of the following
steps:
1. Get the example.jar ready along with proper deployment
descriptors in the META-INF.
2. Deploy the jar into the EJB container/server.
3. Write the remote/local client.
Steps:
1. and 2. Ensure you have this ready under some common directory
or project:
HelloWorldLdap/
EjbLdapbean.class
EjbLdap.class
EjbLdapHome.class
META-INF/
ejb-jar.xml
xyz.xml : optional – usually contains the jndi name used for lookup
by the bean. This needs to be customized for the particular EJB
servers(where the Bean is deployed) like
1. BEA WebLogic 6.0 (Service Pack 2)-> Here the xyz.xml is called
weblogic-ejb-jar.xml
2. JBoss 2.2.1 -> Here the xyz.xml is called jboss.xml
Certain servers provide a GUI tool for deploying an EJB. In that
case, you need not include xyz.xml in the META-INF folder
yourself. The Deployment Wizard will ask you for a jndi lookup
name and auto. create a customized xyz.xml and put the
HelloWorldLdap/
EjbLdapbean.class
EjbLdap.class
EjbLdapHome.class
META-INF/
ejb-jar.xml
xyz.xml
into a jar and deploy it in some specific directory.
If you are not using any GUI tool, like in JBoss or WebLogic, then
you need to add xyz.xml yourself and create a jar using
jar cvf HelloWorldLdap.jar META-INF/ HelloWorldLdap/*.class
and then put this jar in the specific directory of the server. More
details about deployment can be found at:
http://www.javaworld.com/javaworld/jw-08-2001/jw-0803-
ejb.html?page=1
3. Write the remote or the local client to start using the EJB!
A glance at the imports you will need:
import java.io.*;
import java.util.*;
import javax.ejb.EJBHome;
import javax.naming.*; //JNDI
import javax.rmi.PortableRemoteObject;
import org.omg.CORBA.ORB;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import netscape.ldap.*;
Filed under: Tech