How to access an EJB from a JSF application on separate machines?

I have an Enterprise Application with an EJB implementing a @Remote business interface that I would like to access from a JSF managed bean on a different machine. They are both development machines with Netbeans 7 and Glassfish 3.1. I believe the answer lies with CORBA, but I do not think I am doing it right.

Is there a better option then CORBA for this?

Here is where I found how to use corbaname:iiop

This is my EJB Interface:

package remote.ejb;

import javax.ejb.Remote;

public interface HelloRemote {
    public String getHello();

Enterprise Application: RemoteEJBTest Java EE Module: RemoteEJBTest-ejb


package remote.ejb;

import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;

public class HelloBean implements HelloRemote {

    public String getHello() {
        return "Hello World!";

Web Application: RemoteWebTest

package hello.web;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import remote.ejb.HelloRemote;

public class Hello {
    private HelloRemote helloBean;

    private String hello;

    public Hello() throws NamingException {

        InitialContext ctx = new InitialContext();

        Object obj = ctx.lookup("corbaname:iiop:remote_ip:3700#RemoteEJBTest/RemoteEJBTest-egb/HelloBean");
        helloBean = (HelloRemote) PortableRemoteObject.narrow(obj,HelloRemote.class);

    public String getHello(){
        return helloBean.getHello();

Here is the stack trace

relavent parts of stack trace:

com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: hello.web.Hello.
    at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(

Caused by: javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound:]
    at com.sun.jndi.cosnaming.ExceptionMapper.mapException(
    at com.sun.jndi.cosnaming.CNCtx.callResolve(

Caused by: org.omg.CosNaming.NamingContextPackage.NotFound:
    at org.omg.CosNaming._NamingContextStub.resolve(
    at com.sun.jndi.cosnaming.CNCtx.callResolve(
... 59 more

What is the best way to split EJBs over multiple remote machines?


Hum... I think you missed a couple of steps here.

First you need to create a ejb-ref entrance in glassfish-web.xml like this:


Second you reference your ejb name directly.

Context ic = new InitialContext();
Object o = ic.lookup("java:comp/env/ejb/Foo");

And since you are using a Java EE container with EJB 3.1 support, why don't you inject the EJB directly at the managed bean using @EJB (I think it is a lot cleaner than JNDI lookup):

BeanRemoteInterface beanRemoteInterface; 

Take a look here for further info:

Need Your Help

Runtime change Resource Dictionary for a Windows 8.1 XAML Store App

xaml windows-store-apps windows-8.1 winrt-xaml

I am trying to dynamically change my resource dictionary definitions for my application during run time.

Can't read from socket in perl - possible deadlock?

perl sockets

My OS is Archlinux with perl 5.14.2. I am just trying to write a little program to accomplish a remote comlile. The program just passes a C source file to the server. The server will call gcc to co...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.