blob: 1e99f5ccd5ead295bcbbf4b5aac263e52a559514 [file] [log] [blame]
<?xml version="1.0"?>
<document>
<properties>
<title>Using java:comp/env lookups</title>
</properties>
<body>
<section title="Adding ejb-ref in your web.xml">
<p>
An example is best for this. Say you had a block like the
following in your web.xml file.
</p>
<PRE>
&lt;ejb-ref&gt;
&lt;description&gt;
EJB Reference to the bean deployed to OpenEJB
&lt;/description&gt;
&lt;ejb-ref-name&gt;ejb/hello&lt;/ejb-ref-name&gt;
&lt;ejb-ref-type&gt;Session&lt;/ejb-ref-type&gt;
&lt;home&gt;org.acme.HelloHome&lt;/home&gt;
&lt;remote&gt;org.acme.Hello&lt;/remote&gt;
&lt;/ejb-ref&gt;
</PRE>
</section>
<section title="Adding the Ejb in your server.xml">
<p>
To make this ejb refence usable in code by your Servlet or JSP, you need to tell Tomcat
how to link that to an actual EJB deployed into OpenEJB. This is done in the
webapps &lt;Context&gt; section of Tomcat's server.xml file. Here is an example of that:
</p>
<PRE>
&lt;Server&gt;
...
&lt;Context path=...&gt;
...
&lt;Ejb name="ejb/hello"
type="Session"
home="org.acme.HelloHome"
remote="org.acme.Hello"/&gt;
&lt;ResourceParams name="ejb/hello"&gt;
&lt;parameter&gt;
&lt;name&gt;factory&lt;/name&gt;
&lt;value&gt;org.openejb.client.TomcatEjbFactory&lt;/value&gt;
&lt;/parameter&gt;
&lt;parameter&gt;
&lt;name&gt;openejb.naming.factory.initial&lt;/name&gt;
&lt;value&gt;org.openejb.client.LocalInitialContextFactory&lt;/value&gt;
&lt;/parameter&gt;
&lt;parameter&gt;
&lt;name&gt;openejb.ejb-link&lt;/name&gt;
&lt;value&gt;Hello&lt;/value&gt;
&lt;/parameter&gt;
&lt;/ResourceParams&gt;
&lt;/Context&gt;
...
&lt;/Server&gt;
</PRE>
<p>
This would link the name "ejb/hello" to a bean called "Hello" in the OpenEJB container system.
</p>
<p>
For more information see <A HREF="http://www.openejb.org/tomcat-object-factory.html">Leveraging J2EE JNDI Lookups</A>
</p>
</section>
</body>
</document>