ejb2

编辑器加载中...package com.dxz.ejb2; import java.util.Properties; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; public class Test { public static String test_jboss() { System.out .println("==========================================================="); Properties props = new Properties(); props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); props.setProperty("java.naming.provider.url", "localhost:1099"); props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming"); try { InitialContext ctx = new InitialContext(props); Object objRef = ctx.lookup("ejb/helloEJB"); HelloWorldHome home = (HelloWorldHome) PortableRemoteObject.narrow( objRef, HelloWorldHome.class); HelloWorldRemote remote = home.create(); System.out.println(remote.sayHello()); return "OK"; } catch (Exception ex) { ex.printStackTrace(); return "Fail"; } } public static String test_wasce() { System.out .println("==========================================================="); try { InitialContext ctx = new InitialContext(); Object objRef = ctx.lookup("java:comp/env/ejb/helloEJB"); HelloWorldHome home = (HelloWorldHome) PortableRemoteObject.narrow( objRef, HelloWorldHome.class); HelloWorldRemote remote = home.create(); System.out.println(remote.sayHello()); return "OK"; } catch (Exception ex) { ex.printStackTrace(); return "Fail"; } } }
posted on 2012-11-03 15:05  duanxz  阅读(248)  评论(0编辑  收藏  举报