This Post is about creating a remote stateless EJB3 using eclipse helios and deploying it on GlassFish 3 and accessing it from another machine using a Java client
Machine1 <192.168.1.69>
1) Create a new EJB Project <SessionBeanProject>
2) Accept the defaults and press next
3) Make sure that the "EJB Client JAR" check box is not checked, we are going to create our interface manually and press finish
4) Now we are going to create the bean class, right click on your project and choose new Session Bean <CalcSessionBean>
5) Configuration of this bean is stateless and remote, so that it creates automatically the remote interface
6) Add your methods and implementation in the bean class
7) Copy your methods signatures and put it in the remote interface class
What is the base role of the interface?
It will be used in the remote client when we call this bean, and the client has to know what methods are available
The remote interface behaves as an API for the EJB that is used by clients to communicate with the EJB.
Deploy this stateless bean
1) Start GlassFish 3 server
2) Add your EJB project to the server
3) You can see "StatelessBeanProject synchronized", so we know it's deployed
4) View the server log by right clicking on the server - GlassFish Enterprise Server - View Log File
You can see the following
INFO: Portable JNDI names for EJB CalcSessionBean : [
java:global/SessionBeanProject/CalcSessionBean, java:global/SessionBeanProject/CalcSessionBean!calc.CalcSessionBeanRemote]
5) This JNDI name will be used by the remote client to lookup the bean
6) There is another
Non-Portable JNDI names, but we are going to use the Portable one
7) If you went to the Admin console - Applications - you can see your Bean, so we know the bean is deployed
Call the deployed stateless bean methods from a remote client
Machine2 <192.168.1.67>
1) Create a regular Java Project <StatelessBeanClientJavaProject>
2) Add GF server JARs
3) Add GF Client libraries to the project (javaee.jar and appserv-rt.jar)
4) Copy your Remote interface in the project
5) Lookup the bean and call its method from the main method
By placing the Host and Port, we are referencing the machine where the bean is deployed and GlassFish is running. Otherwise the client will try to access localhost and it will fail
port 3700 is the default port for IIOP
Local Beans can not be called from remote clients that are on a different JVM