how to create a remote session EJB from a client

I started from scratch. The only difference I can think of is that instead of making an EJB application, I just made an EJB module for the bean. Otherwise, I think it’s the same.

structure:

thufir@dur:~/NetBeansProjects$ 
thufir@dur:~/NetBeansProjects$ tree HelloLibrary/
HelloLibrary/
├── build.xml
├── nbproject
│   ├── build-impl.xml
│   ├── genfiles.properties
│   ├── private
│   │   └── private.properties
│   ├── project.properties
│   └── project.xml
└── src
    └── hello
        └── HelloBeanRemote.java

4 directories, 7 files
thufir@dur:~/NetBeansProjects$ 
thufir@dur:~/NetBeansProjects$ tree HelloEJB/
HelloEJB/
├── build.xml
├── nbproject
│   ├── ant-deploy.xml
│   ├── build-impl.xml
│   ├── genfiles.properties
│   ├── private
│   │   └── private.properties
│   ├── project.properties
│   └── project.xml
└── src
    ├── conf
    │   └── MANIFEST.MF
    └── java
        └── hello
            └── HelloBean.java

6 directories, 9 files
thufir@dur:~/NetBeansProjects$ 
thufir@dur:~/NetBeansProjects$ tree HelloClient/
HelloClient/
├── build.xml
├── nbproject
│   ├── ant-deploy.xml
│   ├── build-impl.xml
│   ├── genfiles.properties
│   ├── private
│   │   └── private.properties
│   ├── project.properties
│   └── project.xml
├── src
│   ├── conf
│   │   ├── application-client.xml
│   │   └── MANIFEST.MF
│   └── java
│       └── helloclient
│           └── Main.java
└── test

7 directories, 10 files
thufir@dur:~/NetBeansProjects$ 
thufir@dur:~/NetBeansProjects$ 

client code:

package helloclient;

import hello.HelloBeanRemote;
import javax.ejb.EJB;

public class Main {
    @EJB
    private static HelloBeanRemote helloBean;

    public static void main(String... args) {
        System.out.println(helloBean.Hi());
    }

}

bean:

package hello;

import javax.ejb.Stateless;

@Stateless
public class HelloBean implements HelloBeanRemote {

    @Override
    public String Hi() {
        return "hello world";
    }

    @Override
    public String Bye() {
        return "goodbye";
    }

}

remote interface:

package hello;

import javax.ejb.Remote;

@Remote
public interface HelloBeanRemote {
    public String Hi();
    public String Bye();
}

Leave a Comment