1. 程式人生 > >EJB2.0 之 HelloWorld

EJB2.0 之 HelloWorld

 public static void main(String[] args)  
    {  
          
        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());
        }  
        catch (Exception ex)  
        {  
            ex.printStackTrace();  
        }  
    }