Ejb Local And Remote Interfaces : Local Remote « EJB3 « Java

Ejb Local And Remote Interfaces

File: HelloServiceBean.java

import javax.ejb.Stateless;

public class HelloServiceBean implements HelloServiceLocal, HelloServiceRemote {
    public String sayHello(String name) {
        return "Hello1, "  + name;


File: HelloServiceLocal.java

import javax.ejb.Local;

public interface HelloServiceLocal {
    public String sayHello(String name);

File: HelloServiceRemote.java

import javax.ejb.Remote;

public interface HelloServiceRemote{
    public String sayHello(String name);

File: jndi.properties


File: Main.java

import java.util.*;

import javax.naming.*;

public class Main{

   public static void main(String[] a) throws Exception{
        String name = "java2s";
        HelloServiceRemote service = null;

        //Context compEnv = (Context) new InitialContext().lookup("java:comp/env");
        //service = (HelloService)new InitialContext().lookup("java:comp/env/ejb/HelloService");
        service = (HelloServiceRemote)new InitialContext().lookup("HelloServiceBean/remote");



EJB-EjbLocalAndRemote.zip( 4,485 k)

Related examples in the same category

1.Local Interface Without Marking