Page 2 of 4
For your convenience, we have created a zip file containing the HelloWorldLdap and ProfileTest examples discussed in this article, which you can download in Resources.
Our first example is a stateless session bean that retrieves information from an LDAP directory. The user, in this case the client, can specify an alternative LDAP server, email address, and base distinguished name (DN) on the command line, and the EJB will retrieve all attributes for that DN from the specified directory.
Classpath issues can hinder EJB and client compilation. To illustrate that, we chose to add the Netscape LDAP library to our
first example. Basically, you need to compile your EJB code using the j2ee.jar library that comes with the J2EE JDK, or its equivalent (for JBoss, use jboss.jar; for WebLogic, use weblogic.jar) in your classpath. When compiling a client, however, you also need to have the vendor's client libraries in your classpath,
since the client uses an initial context specific to each vendor, as well as your compiled EJB code. Moreover, WebSphere clients
require the deployed EJB jar file on the classpath as well.
After successfully compiling your EJB, you can begin preparing your EJB for deployment. You must have at least one deployment
descriptor in your META-INF directory to deploy your bean. Our one deployment descriptor, ejb-jar.xml, is located in the example's META-INF directory, and jarred up with our EJB class files before deployment. Our first example, HelloWorldLdap.jar, has two directories: HelloWorldLdap and META-INF, both of which are at the same directory level. With the hope of universally deploying our bean, we made an EJB jar package
containing the following:
HelloWorldLdap/
EjbLdapbean.class
EjbLdap.class
EjbLdapHome.class
EjbLdapClient.class
META-INF/
ejb-jar.xml
We packaged our EJB, using a Unix shell, with the following command:
> jar cvf HelloWorldLdap.jar META-INF/ HelloWorldLdap/*.class
We then attempted to deploy HelloWorldLdap.jar on the three aforementioned application servers. The following sections explain what we discovered.
WebLogic has an EJB preparation utility called ejbc (i.e., java weblogic.ejbc). It takes two parameters as input: the name of the jar file that contains the classes and deployment descriptors (e.g.,
HelloWorldLdap.jar), and the name you want to assign to the ejbc compiled jar file (i.e., HelloWeblogic.jar). The ejbc tool is great when your jar file compiles without errors, but can be quite nerve racking when your EJB is not properly constructed.
Nevertheless, ejbc is a good verification tool that helps identify errors prior to EJB deployment. If you compile your jar file with ejbc, you can feel confident that your EJB will deploy successfully on WebLogic.
We also experimented with deploying the same jar file without using ejbc. With simple EJBs, you might be successful, but hot deploying (updating an EJB without having to stop and restart the application server, or without having to first remove the old bean
instance) your EJB will not work without using ejbc. Moreover, you will not get ejbc's verification that you can deploy successfully.