Instructions on how to deploy a stateless session bean

Remember to leave no spaces in the paths.

  1. Install jboss 3.2.3
  2. Install xdoclet 1.2.3 (from http://xdoclet.sourceforge.net)
  3. Install lomboz (either into an existing eclipse or install the version that comes with an eclipse)
  4. You need to have a JDK 1.4.2 installed too.
  5. If you don't have it already, add the 1.4.2 JRE to the JRE definitions of eclipse.
  6. In Window->Preferences, find xdoclet, it should be within J2EE annotations, and set the version to 1.2.3, and browse to where you installed xdoclet.
  7. Expand Xdoclet and select ejbdoclet. Check JBoss and select version 2.3.
  8. In Window->Preferences, select server, installed runtimes.
  9. Add a new runtime with:
    1. Type Generic JBoss 3.2.3(Generic)
    2. Your JBoss home
    3. Your JBoss home
  10. Change to J2EE perspective and go to the Servers tab and add a server with the runtime that was specified in 9.
  11. It should start and stop without problems.
  12. Right-click on EJB Projects and select New- EJB Project
  13. Specify:
    1. Name SuDuelKuTestEJB
    2. EJB version: 2.0
    3. Target server: Generic JBoss 3.2.3(Generic)
    4. Check Add module to EAR and Create EJB client JAR (although we won't use the EAR, the JAR is very useful)
  14. Click finish

  1. Right-click on the EJB project and add New -> Enterprise Java Bean
  2. Select Session Bean
  3. Select:
    1. Project: SuDuelKuTestEJB
    2. Module name: same
    3. Folder: keep the default
    4. Package: you choose
    5. Class Name: any name, but add Bean at the end of the name
  4. Click next
    1. Here we would choose the attributes of the bean. For now, everything stays the same.
  5. Click finish
  6. All the interfaces and the bean class are generated. The beauty of Lomboz is that you only need to change the NameBean class and everything gets updated with the xdoclet tags.
  7. Open your class definition NameBean.java
  8. Change the signature of method foo to receive something and return something interesting so we can check it later. When you save, an ant file should be run automatically.

Deploy the ejb:

  1. This is the tricky part, hopefully there are no problems.
  2. Open the folder with enterprise applications
  3. Delete the EAR application that was created. Go ahead and delete the contents too.
  4. Go to the servers tag and right-click on the server, and select Add and Remove Projects.
  5. Select your bean and add it to the configured projects. (if we hadn't deleted the EAR, we wouldn't be able to do this, we would have to add all of the EAR to the server, and the EAR has a couple of empty deployment descriptors for the web part of the application).
  6. Select finish.
  7. Start the server and hope for no exceptions!

Some problems I encountered and their solutions:

  1. If you get the message: enterprise-beans tag expected, it means that you are deploying the whole EAR application. We only want to deploy the EJB jar.
  2. If you get the message: EJB spec violation, the methods in the remote interface must have a matching method in the bean's class. If your classes are correct, then it might be that the jars that are copied to the deploy directory of jboss are not being updated. Remove the project from the server, stop the server, select Project -> Clean, and clean both the EJB and the Client projects. Then redeploy the app. The problem should be gone.

Create the client:

  1. The client project is already created, from when we created the EJB project.
  2. Add JBoss client jar to the classpath.
    1. Right-click the project, select properties. In Java Build Path, select add external Jars.
    2. Find and add jbossall-client.jar on your JBOSS_HOME\client.
  3. Add a new class.
  4. Edit the class to include something similar to the code in the following table.
    1. Note that YouWin was the name of my bean, and is the remote interface class. YouWinHome is the home interface that will give us the instance of the bean we will use (with create).
    2. getContext() is a method that will give us our initial context (JNDI) to search for our bean. Those urls, classes and prefixes are specific to JBoss. The JNDI port and address is the default.
    3. getHome returns an instance of our home interface.
  5. Finally, call your EJB with some parameters, run the client as a standalone java application and hope for the best!