javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
客户端调用程序如下:
package com.tele.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.servlet.http.HttpServletRequest;
import com.sxtel.customercard.entity.AllDetailScore;
import com.sxtel.ejbinterface.scorecardserver.EJBSxtelWeb;
import com.sxtel.ejbinterface.scorecardserver.EJBSxtelWebHome;
import com.sxtel.ejbinterface.scorecardserver.OperatorIF;
  public   class   ScoreCardServerClient {   
  static EJBSxtelWeb serverBean = null;
  public   static   void   main(String[] args){ 
//   HttpServletRequest request;
String filePath = "D:\\CVSclient\\Operator_Point_Manager\\pointCardWeb\\WEB-INF\\";// ȡ��ǰϵͳ·??
// String filePath = request.getRealPath("/");// ȡ��ǰϵͳ·??
String fileName = filePath + "Jndi.properties";
System.out.println("File Name:" + fileName);
try
{
Properties prop = new Properties();
FileInputStream inputFile = new FileInputStream(fileName);
prop.load(inputFile);
System.out.println("读取jndi文件中的内容:webAppFactory=" + prop.getProperty("webAppFactory"));
System.out.println("读取jndi文件中的内容:iiop=" + prop.getProperty("iiop"));
System.out.println("读取jndi文件中的内容:webAppName=" + prop.getProperty("webAppName"));
System.out.println("读取jndi文件中的内容:jndiName=" + prop.getProperty("jndiName"));
// System.out.println("��ȡjndi�ļ��е����ݣ�webAppFactory=" + prop.getProperty("webAppFactory")); inputFile.close(); Hashtable params = new Hashtable();
// params.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
params.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, prop
.getProperty("webAppFactory"));
params.put(javax.naming.Context.PROVIDER_URL, prop
.getProperty("iiop"));
params.put(javax.naming.Context.URL_PKG_PREFIXES, prop
.getProperty("webAppName"));
// params.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
// params.put(javax.naming.Context.PROVIDER_URL, "iiop://133.64.39.216:2810");
// params.put(javax.naming.Context.PROVIDER_URL,
// "iiop://127.0.0.1:2809");
// params.put(javax.naming.Context.URL_PKG_PREFIXES,"EJBSxtelWeb");
System.out.println("---调用EJB的接口之前的语句,打印参数值:"+params);
Context jndiContext = new InitialContext(params);
System.out.println("---调用EJB的接口之前的语句,打印jndiContext="+jndiContext+",jndiName="+prop.getProperty("jndiName")); Object ref = jndiContext.lookup("java:comp/env/ejb/"+prop.getProperty("jndiName"));//突破点之一。。
// Object ref = jndiContext.lookup("cell/node1/servers/server1/ejb/ejbs/"+prop.getProperty("jndiName"));//突破点之一。。
// Object ref = jndiContext.lookup("java:comp/env/ejb/"+prop.getProperty("jndiName"));//突破点之一。。
System.out.println("调用EJB的接口后的返回对象的打印:ref=" + ref); EJBSxtelWebHome home = (EJBSxtelWebHome) PortableRemoteObject.narrow(ref, EJBSxtelWebHome.class);
System.out.println("Successfully get ejb.");
serverBean = home.create();
} catch (java.rmi.RemoteException re)
{
re.printStackTrace();
} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} catch (Throwable t)
{
t.printStackTrace();
}
  }
}jndi.properties:# Resources for Jndi properties.
# Project P/main
webAppFactory=com.ibm.websphere.naming.WsnInitialContextFactory
iiop=iiop://133.64.39.216:2811
webAppName=com.ibm.ws.naming
jndiName=EJBSxtelWeb其中133.64.39.216是调用的WebSphere主机名称,2811是BOOTSTRAP_ADDRESS 的端口,EJBSxtelWeb是接口名称

解决方案 »

  1.   

    URL name in a JNDI Context method call but is not running in a J2EE client or server environment. 133.64.39.216是调用的WebSphere主机名称主机没运行?
      

  2.   

    主机运行了,就是那个IP,应该是配置的错误,不知道在哪。。
    遇到这样一个文件ibm-ejb-jar-bnd.xmi,内容如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <ejbbnd:EJBJarBinding xmlns:ejbbnd="ejbbnd.xmi" xmlns:xmi="http://www.omg.org/XMI" xmlns:ejb="ejb.xmi" xmlns:common="common.xmi" xmlns:commonbnd="commonbnd.xmi" xmi:version="2.0" xmi:id="ejb-jar_ID_Bnd">
      <ejbJar href="META-INF/ejb-jar.xml#ejb-jar_ID"/>
      <ejbBindings xmi:id="Session_BND_1161960899031" jndiName="">
        <enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml#Session_1158045297875"/>
      </ejbBindings>
    </ejbbnd:EJBJarBinding>
    这里面的jndiName=""不知怎么改,还有.xmi文件怎么修改呢?没见过这种文件