How use lookup method to find simple bean that return String "hello world".
The folder structure within the Ejb-jar file looks as follows:
META-INF/
META-INF/MANIFEST.MF
examples/
examples/HelloBean.class
examples/HelloHome.class
examples/Hello.class
examples/HelloLocal.class
examples/HelloLocalHome.class
META-INF/ejb-jar.xml
J have write a class HelloClient
public class HelloClient {
public static void main(String[] args) throws Exception {
Properties props = System.getProperties();
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("HelloHome");
HelloHome home = (HelloHome)
javax.rmi.PortableRemoteObject.narrow(
obj, HelloHome.class);
Hello hello = home.create();
System.out.println(hello.hello());
hello.remove();
}
}
but this
Object obj = ctx.lookup("HelloHome");
Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at example.HelloClient.main(HelloClient.java:36)