Table of Contents
Author:[email protected]>
<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.
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:
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/TravelAgentBean.java, and replace
Object obj = jndiContext.lookup("ejb/CabinHome");with
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"?> <jboss> <enterprise-beans> <session> <ejb-name>TravelAgentBean</ejb-name> <ejb-ref> <ejb-ref-name>ejb/CabinHome</ejb-ref-name> <jndi-name>CabinBean</jndi-name> </ejb-ref> </session> </enterprise-beans> </jboss>
You don't jave to change anything in ejb-jar.xml. You can now use the following script jbossMakeIt.sh to compile and deploy:
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/Client_1.java replace
Object obj = jndiContext.lookup("java:comp/env/ejb/CabinHome");by
Object obj = jndiContext.lookup("CabinBean");In com/titan/cabin/Client_2.java replace
Object obj = jndiContext.lookup("ejb/CabinHome");by
Object obj = jndiContext.lookup("CabinBean");In com/titan/travelagent/Client_1.java replace
Object obj = jndiContext.lookup("ejb/TravelAgentHome");by
Object obj = jndiContext.lookup("TravelAgentBean");You can now use jBossMakeClients.sh to compile:
We don't use Sun's RI runclient tool, so RunIt.sh won't work. Instead, we provide the following script: jBossRunClient.sh. This file includes all the jBoss libraries needed in the classpath.
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.provider.url=localhost java.naming.factory.url.pkgs=org.jboss.naming;You can now run the clients. The script take the name of the client as an argument, try
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".