Exception in thread "main" javax.naming.NoInitialContextException: Need to speci

 

今天做Ejb3.0的例子时候,使用客户端通过JNDI的方式调用EJB,

Context context = new InitialContext();
HelloEjb helloEjb = (HelloEjb) context.lookup("HelloEjbBean/remote");
String result = helloEjb.sayHello("ZhouHaiTao");
System.out.println(result);

报下面这个错误,原因是因为忘记在classPath下面添加jndi.properties文件,导致报错,

 

解决方案:

在客户端classPath下添加jndi.properties文件,内容如下:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost --服务器地址.

 

然后,重新运行,问题解决.

 

 

错误:

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 pack.java.ejb.client.HelloEjbClient.main(HelloEjbClient.java:21)

你可能感兴趣的:(exception)