magic,如果你不设置initial context的参数:javax.naming.Context.INITIAL_CONTEXT_FACTORY和javax.naming.Context.PROVIDER_URL,谁知道你要访问哪个服务器的jndi

解决方案 »

  1.   

    我修改了代码,加上了几句 env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
     env.put(Context.PROVIDER_URL, "iiop://127.0.0.1:4848"); Context initial = new InitialContext(env);
     Object objref= initial.lookup("java:comp/env/ejb/SimpleConverter"); ConverterHome home =(ConverterHome) PortableRemoteObject.narrow(objref,
                        ConverterHome.class); Converter currencyConverter = home.create();错误转换成如下:javax.naming.CommunicationException: Cannot connect to ORB [Root exception is org.omg.CORBA.COMM_FAILURE:   vmcid: SUN  minor code: 208 completed: Maybe]