我从来没有亲自做过,因为我喜欢用同一个JVM中的本地接口,它可以提高性能大幅提升。
但是你可以看看这个:
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB
不过你可以试试这个:
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
// optional. Defaults to localhost. Only needed if web server is running
// on a different host than the appserver
props.setProperty("org.omg.CORBA.ORBInitialHost", "ejb_server_ip_or_host_name");
// optional. Defaults to 3700. Only needed if target orb port is not 3700.
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ic = new InitialContext(props);
步骤2.使用在目标远程EJB的全局JNDI名称抬头。
EJB 3.x中,假设 “com.acme.FooRemoteBusiness” 的全局JNDI名称:
FooRemoteBusiness foo = (FooRemoteBusiness) ic.lookup("com.acme.FooRemoteBusiness");
EJB 2.x中,假设 “com.acme.FooHome” 的全局JNDI名称:
Object obj = ic.lookup("com.acme.FooHome");
FooHome fooHome = (FooHome) PortableRemoteObject.narrow(obj, FooHome.class);
可能重复[我如何可以部署会话Bean与另一台计算机与客户端JSP/Servlet](http://stackoverflow.com/questions/3614802/how-can-i-deploy-session-bean-on -otherother-computer-with-client-jsp-servlet) – 2010-09-04 20:01:56
检查出来 - 完整的示例:http://stackoverflow.com/questions/4763960/accessing-a-无状态的EJB-从-另一个实例-的-的GlassFish/10194057#10194057 – 2012-04-17 18:09:26