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){ } } }