EJB2.0 之 HelloWorld
阿新 • • 發佈:2019-02-19
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();
}
}
{
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();
}
}