Saturday, May 22, 2010

Foreign JNDI provider - call remote EJB

Create two domains - base_domain and remote_domain.

Setup Foreign JNDI provider on base_domain pointing to remote_domain.

Create session EJB calling remote session EJB and deploy to base_domain.
package testEAR;

import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import remoteEAR.RemoteEJBRemote;

* Session Bean implementation class CallRemoteBean
public class CallRemoteBean implements CallRemoteBeanLocal {

public CallRemoteBean() {

public void callRemoteBean(){

RemoteEJBRemote remoteEJB = null;
try {
remoteEJB = (RemoteEJBRemote)new InitialContext().lookup("RemoteEJB");
} catch (NamingException e) {
System.out.println("Calling remote");
String response = remoteEJB.hello();

System.out.println("Response remote=" + response);



Create session bean on remote_domain

package remoteEAR;

import javax.ejb.Stateless;

* Session Bean implementation class RemoteEJB
@Stateless(mappedName = "RemoteEJB")
public class RemoteEJB implements RemoteEJBRemote {

* Default constructor.
public RemoteEJB() {

public String hello(){
System.out.println("In remote");
return "Hello from remote";


All projects created in Eclipse 3.5

EJB3 reference injection problems

1 comment:

  1. Hi, could you tell me how to configure the "Remote JNDI Name" field? In your snapshot the information is truncated.

    Thank you!