1. Test.java 程序如下:
import java.rmi.RemoteException; import java.util.Properties; import javax.ejb.CreateException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; import com.bohai.first.ejb.TreadeBeanHome; import com.bohai.first.ejb.TreadeBeanRemote; public class Test { /** * @param args */ public static void main(String[] args) { Properties prop=new Properties(); prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory"); prop.setProperty(Context.PROVIDER_URL, "localhost:1099"); prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming"); prop.setProperty(Context.SECURITY_PRINCIPAL, ""); prop.setProperty(Context.SECURITY_CREDENTIALS, ""); try{ InitialContext ic=new InitialContext(prop); Object obj=ic.lookup("TreadeBean"); TreadeBeanHome home=(TreadeBeanHome)PortableRemoteObject.narrow(obj, TreadeBeanHome.class); TreadeBeanRemote remote = home.create(); System.out.println(remote.sayHello()); }catch (NamingException ne) { ne.printStackTrace(); System.out.println("测试一下!!"); }catch(CreateException ce){ }catch(RemoteException re){ } } }
本文介绍了一个使用 Java 进行 EJB (Enterprise JavaBeans) 远程调用的例子。该示例展示了如何配置 JNDI (Java Naming and Directory Interface) 属性并查找远程 EJB 对象,通过窄化过程转换为特定接口类型,进而调用远程方法。
414

被折叠的 条评论
为什么被折叠?



