EJBs can be accessed with RMI or as SOAP-RESTful endpoint. I want to access a remote EJB from another computer/ip address for example in a standalone application. I can reach to EJBs with web services endpoint then i dont know to reach with RMI. How can i implement this idea. I'm using Glassfish 3.1.
Asked
Active
Viewed 869 times
1 Answers
0
Check out the How do I access a Remote EJB component from a stand-alone java client? document. Code snippets rely on EJB 2 (Home
interfaces), you should lookup @Remote
interfaces directly. Of course they must be available on the client side.
Example
Based on: Creating EJB3 Sessions Beans using Netbeans 6.1 and Glassfish:
jndi.properties
:
java.naming.factory.initial = com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs = com.sun.enterprise.naming
java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
org.omg.CORBA.ORBInitialHost = localhost
org.omg.CORBA.ORBInitialPort = 3700
Main.java
:
package testclient;
import java.io.FileInputStream;
import java.util.Properties;
import javax.naming.InitialContext;
import stateless.TestEJBRemote;
public class Main {
public static void main(String[] args) {
try {
Properties props = new Properties();
props.load(new FileInputStream("jndi.properties"));
InitialContext ctx = new InitialContext(props);
TestEJBRemote testEJB = (TestEJBRemote) ctx.lookup("stateless.TestEJBRemote");
System.out.println(testEJB.getMessage());
} catch (NamingException nex) {
nex.printStackTrace();
} catch (FileNotFoundException fnfex) {
fnfex.printStackTrace();
} catch (IOException ioex) {
ioex.printStackTrace();
}
}
}
See also

Community
- 1
- 1

Tomasz Nurkiewicz
- 334,321
- 69
- 703
- 674
-
Can i find a running example? im little complicated. – Rahman Usta Feb 03 '12 at 19:38
-
@RahmanUsta: I added (hopefully working) example based on [Creating EJB3 Sessions Beans using Netbeans 6.1 and Glassfish](http://wiki.netbeans.org/CreatingEJB3UsingNetbeansAndGlassfish). – Tomasz Nurkiewicz Feb 03 '12 at 20:58
-
http://netbeans.dzone.com/nb-call-ejb-on-glassfish This is best article, thanks. – Rahman Usta Feb 20 '12 at 17:32