Chapter 12. Third Party Examples

Table of Contents

Running the Examples from Enterprise JavaBeans, by Richard Monson-Haefel (Unix)
Deploying the Pet Store 1.1.2 Demo in JBoss
Deploying Cocoon 2 in JBoss
Using SSL with JBoss

Running the Examples from Enterprise JavaBeans, by Richard Monson-Haefel (Unix)

Author:Sebastien Alborini <>

This page describes how to run the examples from Richard Monson-Haefel's book Enterprise JavaBeans, 2nd Edition (Chapter 4) in JBoss.

You can download the examples (zip file) from O'Reilly's site. I will assume you have unzipped this file and you work in the chapter4/EJB11 directory.

These examples need to be slightly modified to run with JBoss. You can download the modified version here, but I recommend you to follow these instructions which tell exactly what has to be modified.

  • Setup your environment.

    JBoss libraries will be needed to compile and run the examples, so you have to set the environment variable JBOSS_HOME to your JBoss installation. For example:

    • export JBOSS_HOME=$HOME/jboss_pr4 if you have the binary version in your home directory

    • export JBOSS_HOME=$HOME/jboss/dist if you have the CVS version.

  • Compile and deploy the beans.

    The beans are almost ok for JBoss, the only difference is about the reference made by TravelAgentBean to CabinBean: a bean must lookup in the java:comp/env namespace. Edit com/titan/travelagent/, and replace

         Object obj = jndiContext.lookup("ejb/CabinHome");
         Object obj = jndiContext.lookup("java:comp/env/ejb/CabinHome"); 

    This ejb-reference from TravelAgentBean (in travelagent.jar) to CabinBean (in cabin.jar) is an external reference (different ejb-jar file). You must then provide the full jndi name for CabinBean in a jboss.xml for TravelAgentBean: create and edit com/titan/travelagent/jboss.xml

         <?xml version="1.0"?>                                                 

    You don't jave to change anything in ejb-jar.xml. You can now use the following script to compile and deploy:



         # make cabin bean

         javac -classpath $JBOSS_HOME/lib/ext/ejb.jar:. \

         cp com/titan/cabin/ejb-jar.xml META-INF/ejb-jar.xml
         jar cvf cabin.jar com/titan/cabin/Cabin*.class META-INF/ejb-jar.xml

         # make travelagent bean

         javac -classpath $JBOSS_HOME/lib/ext/ejb.jar:. \

         cp com/titan/travelagent/ejb-jar.xml \
            com/titan/travelagent/jboss.xml \

         # JBoss needs the Home, Remote and primary key (PK) classes
         # of the Cabin in travelagent.jar so that TravelAgent*.class
         # can access the Cabin bean

         jar cvf travelagent.jar \
           com/titan/cabin/CabinHome.class \
           com/titan/cabin/Cabin.class \
           com/titan/cabin/CabinPK.class \
           com/titan/travelagent/TravelAgent*.class \
           META-INF/ejb-jar.xml META-INF/jboss.xml

         rm -f META-INF/ejb-jar.xml
         rm -f META-INF/jboss.xml

         # deploy
         cp cabin.jar travelagent.jar $JBOSS_HOME/deploy

  • Compile the clients.

    The clients from the examples perform a lookup on the java:comp/env namespace, which is not currently supported by JBoss for the clients. You have to make the following edits: (CabinBean is the jndi name under which the Cabin Bean is deployed, see the jndi howto) In com/titan/cabin/ replace

         Object obj = jndiContext.lookup("java:comp/env/ejb/CabinHome");
         Object obj = jndiContext.lookup("CabinBean");
    In com/titan/cabin/ replace
         Object obj = jndiContext.lookup("ejb/CabinHome");
         Object obj = jndiContext.lookup("CabinBean");
    In com/titan/travelagent/ replace
         Object obj = jndiContext.lookup("ejb/TravelAgentHome");
         Object obj = jndiContext.lookup("TravelAgentBean");
    You can now use to compile:

         javac -classpath $JBOSS_HOME/lib/ext/ejb.jar:.  \
             com/titan/cabin/Client*.java                \


  • Run the clients

    We don't use Sun's RI runclient tool, so won't work. Instead, we provide the following script: This file includes all the jBoss libraries needed in the classpath.




         java -cp $CP $1
    You also have to set the jndi properties to connect to the server. This is done in the file (this file must be in the same directory as
    You can now run the clients. The script take the name of the client as an argument, try
         ./ com.titan.cabin.Client_1
         ./ com.titan.cabin.Client_2
         ./ com.titan.travelagent.Client_1

    NOTES: the clients will only run once, since they use the EJBHome.create() method: at second run, a DuplicateKeyException will occur. I recommend you to turn off debug logging for these examples. Edit $JBOSS_HOME/conf/jboss.conf, in the ConsoleLogging section, set the first ARG to "Error".