User Guide

Table Of Contents
938 Chapter 37: Integrating J2EE and Java Elements in CFML Applications
Using an EJB
ColdFusion MX can use EJBs that are served by JRun 4.0 servers. The JRun server jrun.jar file
must have the same version as the jrun.jar file in ColdFusion.
To call an EJB, you use
cfobject type="Java" to create and call the appropriate objects. Before
you can use an EJB you must do the following:
1.
Have a properly deployed EJB running on a J2EE server. The bean must be registered with the
JNDI server.
2.
Have the following information:
Name of the EJB server
Port number of the JNDI naming service on the EJB server
Name of the EJB, as registered with the naming service
3.
Install the EJB home and component interface compiled classes on your ColdFusion web server,
either as class files in the web_root/WEB-INF/classes directory or packaged in a JAR file the
web_root/WEB-INF/lib directory.
Note: To use an EJB served by a JRUN server, your ColdFusion installation and the JRun server that
hosts the EJB must have the same version of the jrun.jar file (located in cf_root\runtime\lib directory in
ColdFusion).
Although the specific steps for using an EJB depend on the EJB server and on the EJB itself, they
generally correspond to the following order.
To use an EJB:
1.
Use the cfobject tag to create an object of the JNDI naming context class
(javax.naming.Context). You will use fields from this class to define the information that you
use to locate the EJB. Because you only use fields, you do not initialize the object.
2.
Use the cfobject tag to create a java.util.Properties class object that will contain the context
object properties.
3.
Call the init method to initialize the Properties object.
4.
Set the Properties object to contain the properties that are required to create an initial JNDI
naming context. These include the INITIAL_CONTEXT_FACTORY and
PROVIDER_URL properties. You might also need to provide SECURITY_PRINCIPAL and
SECURITY_CREDENTIALS values required for secure access to the naming context. For
more information on these properties, see the JNDI documentation.
5.
Use the cfobject tag to create the JNDI InitialContext (javax.naming. InitialContext) object.
6.
Call the init method for the InitialContext object with the Properties object values to initialize
the object.
7.
Call the InitialContextext object’s lookup method to get a reference to the home interface for
the bean that you want. Specify the JNDI name of the bean as the
lookup argument.
8.
Call the create method of the bean’s home object to create a new instance of the bean. If you
are using Entity beans, you typically use a finder method instead. A finder method locates one
or more existing entity beans.