类似:/*
 *
 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * This software is the proprietary information of Sun Microsystems, Inc.  
 * Use is subject to license terms.
 * 
 */import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.math.BigDecimal;public class ConverterClient {   public static void main(String[] args) {
       try {
           Context initial = new InitialContext();
           Context myEnv = (Context)initial.lookup("java:comp/env");
           Object objref = myEnv.lookup("ejb/SimpleConverter");           ConverterHome home = 
               (ConverterHome)PortableRemoteObject.narrow(objref, 
                                            ConverterHome.class);           Converter currencyConverter = home.create();           BigDecimal param = new BigDecimal ("100.00");
           BigDecimal amount = currencyConverter.dollarToYen(param);
           System.out.println(amount);
           amount = currencyConverter.yenToEuro(param);
           System.out.println(amount);           System.exit(0);       } catch (Exception ex) {
           System.err.println("Caught an unexpected exception!");
           ex.printStackTrace();
       }
   } 

解决方案 »

  1.   

    同时,在JB里面可以创建EJB Client用于测试EJB!!!所以,你通过EJB Client,分析其JNDI结构,问题迎刃而解!!!:)——
      

  2.   

    我建议你去下载J2EE教程,里面都有!!!
    http://java.sun.com/j2ee
      

  3.   

    本机掉本机的ejb我会用
    另外机子我就不会了
      

  4.   

    package com.tiptopone.user.player.online;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2002</p>
     * <p>Company: </p>
     * @author unascribed
     * @version 1.0
     */
    import javax.ejb.*;
    import javax.naming.*;
    import java.rmi.*;
    import java.util.Properties;
    import javax.rmi.PortableRemoteObject;public class HelloClient {  public HelloClient() {
      }
      public static void main(String[] args) {
          try{
            Properties props = System.getProperties();        props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.TengahInitialContextFactory");
            props.put(javax.naming.Context.PROVIDER_URL,"t3://localhost:41766");        Context ctx = new InitialContext(props);
            Object objref = ctx.lookup("Hello");//Lookup the JNDI name
            HelloHome Home = (HelloHome)PortableRemoteObject.narrow(objref, HelloHome.class);
            Hello hello = Home.create();        System.out.println(hello.hello());
            hello.remove();
          }catch(Exception e){
            e.printStackTrace();
          }  }
    }
    我是这样写的,为什么会不行???
      

  5.   

    访问另一台机器上的??如果是,怎么:t3://localhost:41766
      

  6.   

    各位大侠,你们好,小弟在学习EJB时碰到了一个问题,请贵手指点一下:
    客户端代码(ConverterClient.java):
      ...
     java.util.Hashtable properties = new java.util.Hashtable();
       properties.put(Context.PROVIDER_URL, "http://192.168.0.111:9191/");
       Context initial = new InitialContext( properties );
       Object objref = initial.lookup("MyConverter")   ...其中:chenshq 是EJB服务器所在的地址  
         9191 是监听端口
         MyConverter 是在布署时给的JNDI的名字    
      

  7.   

    快帮帮我啊
    我是指脱离了weblogic 就不行了啊,
      

  8.   

    出错信息是:
    java.lang.UnsupportedOperationException: Method setSessionContext() not yet implemented.
    at weblogic.rmi.internal.AbstractOutboundRequest.sendReceive(AbstractOutboundRequest.java:90)
    at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:247)
    at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:225)
    at com.tiptopone.user.player.online.HelloBeanEOImpl_WLStub.hello(HelloBeanEOImpl_WLStub.java:143)
    at com.tiptopone.user.player.online.HelloClient.main(HelloClient.java:33)
      

  9.   

    你在EJB客户端,有没有EJB存更??
      

  10.   

    EJB的调用建立在RMI-IIOP的基础上,在EJB Client和EJB Server都需要的动!
      

  11.   

    把hello.hello();这句去掉不会出错,加上就出错。:(
      

  12.   

    Method setSessionContext() not yet implemented.
    是指哪个类的方法没有实现???
      

  13.   

    就是说在配置EJB时会提示是否返回client短的.jar,所以需要在你的客户短加入该.jar的路径
      

  14.   

    好了,是我没有把
     public void ejbRemove() throws javax.ejb.EJBException, java.rmi.RemoteException {
        /**@todo: Implement this javax.ejb.SessionBean method*/
        throw new java.lang.UnsupportedOperationException("Method ejbRemove() not yet implemented.");
      }
    里面的throw去掉的缘故,呵呵