Monday, January 22, 2007

Using global-jndi-lookup-enable to lookup EJBs across applications

OC4J 10.1.3.1 allows lookup of EJBs across application by enabling the global JNDI lookup.

To use the global JNDI feature in OC4J, first you have to enable it.
1. Using a text editor, open config/server.xml.
2. Within the <application-server> element, add the global-jndi-lookup-enabled attribute and set it to true as follows:

<application-server global-jndi-lookup-enabled="true">
</application-server>

3. Save and close server.xml.

4. Restart the application server.

5. Deploy application that contains the EJB. Let us say the application name is APP2 that contains a remote EJB with JNDI location “EmployeeFacadeBean”.

To find the JNDI location look at the generated orion-ejb-jar.xml in the server’s application deployment directory. To configure a different JNDI location package an orion-ejb-jar.xml as follows:

<session-deployment name="EmployeeFacadeBean">
name="EmployeeFacadeBean" location="EmployeeFacadeBean"

</session-deployment >

The default JNDI name is the name of the remote interface of the session bean configured using the ejb-name element in ejb-jar.xml or name element of @Stateless or @Stateful annotations.

The client application that looks up the EJB must package the remote, home, interfaces to look up the remote EJB.

You can lookup the EJB from the client application using the JNDI location as follows:

Context ctx = new InitialContext();
employeeFacade = (EmployeeFacade) ctx.lookup("EmployeeFacadeBean");


Now you deploy your client application and the application should be able to lookup the EJB in APP2!

If you want to use in OC4J 10.1.3.0.0 then make sure that you apply 10.1.3.1 patchset!

2 comments:

sam said...

when should one be using the global-jndi-lookup-enable. Any documentation reference that lists the details or any sample applications that can be refered to.

Anonymous said...

I have web application deployed on a Oracle Application server and an EJB application deployed on a Websphere Application Server. I need to lookup the EJB's from the web application with the InitialContext.
Do you know what and how I must configure the Oracle application server to do that.
The Oracle is an 10.1.3.1 and the Websphere is an version 6.1