这个方法只是在本机上可以.
客户端和你的服务器在一台机子上,所以可以直接查找到你的jndi名字 .
如果是远程的客户端,则必须指定具体的 ip地址和服务器参数 .

解决方案 »

  1.   

    类似下面这样吗?
    Object obj = ctx.lookup("server:port/ejb/myejb");
      

  2.   

    Hashtable ht = new Hashtable();
    ht.put(ctx.PROVIDER_URL, "t3://ip:port");
        ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        ctx = new InitialContext(ht);
      

  3.   

    properties p=new properties()
    p.put(ctx.PROVIDER_URL, "t3://ip:port");
    ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        ctx = new InitialContext(ht);java.naming.context ctx=(java.naming.context)new javax.naming.initialcontext(p)
      

  4.   

    public static Context getInitialContext() throws Exception {
        String url = "t3://ip:port";
        String user = null;
        String password = null;
        Properties properties = null;
        try {
          properties = new Properties();
          properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
          properties.put(Context.PROVIDER_URL, url);
          if (user != null) {
            properties.put(Context.SECURITY_PRINCIPAL, user);
            properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
          }      return new InitialContext(properties);
        }
        catch(Exception e) {
          System.out.println("Unable to connect to WebLogic server at " + url);
          System.out.println("Please make sure that the server is running.");
          throw e;
        }
      }