Using java:comp/env lookups

|  |  |  | OpenEJB OpenJMS OpenORB Castor Tyrex |

Main
Welcome!
Download
Mailing Lists
The Team

Users
Quickstart
Hello World!
CMP Example
CMP Guide
Deploy
Startup
Validation
Configuration
Support
Request Feature
FAQ

Servers
Local Server
Remote Server
Tomcat

Integrators
Why OpenEJB
Overview
Design
Specification
Presentation

Developers
Custom Services
Release Plan
Source Code
SourceForge

Using java:comp/env lookups

Adding ejb-ref in your web.xml
Adding the Ejb in your server.xml

## Adding ejb-ref in your web.xml

An example is best for this. Say you had a block like the following in your web.xml file.

    <ejb-ref>
        <description>
            EJB Reference to the bean deployed to OpenEJB
        </description>
        <ejb-ref-name>ejb/hello</ejb-ref-name>
        <ejb-ref-type>Session</ejb-ref-type>
        <home>org.acme.HelloHome</home>
        <remote>org.acme.Hello</remote>
    </ejb-ref>

## Adding the Ejb in your server.xml

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 <Context> section of Tomcat's server.xml file. Here is an example of that:

    <Server>
        ...
        <Context path=...>
            ...
            <Ejb name="ejb/hello"
                 type="Session"
                 home="org.acme.HelloHome"
                 remote="org.acme.Hello"/>
            <ResourceParams name="ejb/hello">
                <parameter>
                    <name>factory</name>
                    <value>org.openejb.client.TomcatEjbFactory</value>
                </parameter>
                <parameter>
                    <name>openejb.naming.factory.initial</name>
                    <value>org.openejb.client.LocalInitialContextFactory</value>
                </parameter>
                <parameter>
                    <name>openejb.ejb-link</name>
                    <value>Hello</value>
                </parameter>
            </ResourceParams>
        </Context>
        ...
    </Server>

This would link the name "ejb/hello" to a bean called "Hello" in the OpenEJB container system.

For more information see Leveraging J2EE JNDI Lookups

Java, EJB, JDBC, JNDI, JTA, Sun, Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries. XML, XML Schema, XSLT and related standards are trademarks or registered trademarks of MIT, INRIA, Keio or others, and a product of the World Wide Web Consortium. All other product names mentioned herein are trademarks of their respective owners.