Posts Tagged ‘jndi’

How to reference a ejb 3.1 from another web application running in the same vm

abril 30, 2011

Given the bean :

— interface

package com.amhom.ejb.customer;


import javax.ejb.Local;

public interface Customer extends Serializable {
public String getTestString();

— implementation

package com.amhom.ejb.customer;

import javax.annotation.Resource;
import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.sql.DataSource;

* Session Bean implementation class Customer
public class CustomerBean implements Customer {
public String getTestString() {
return sayHello();

you can obtain a reference to this EJB from another webapp running on the same vm as GlassFish Server 3 writing:

Customer converter = (Customer) (new InitialContext()).lookup("java:module/CustomerService");

See also: Local Clients