// Remote Interface : Hello.class
import java.rmi.RemoteException;
public interface Hello extends javax.ejb.EJBObject
{
  public String hello() throws java.rmi.RemoteException;
}// Home Interface : HelloHome.class
import javax.ejb.*;
import java.rmi.RemoteException;
public interface HelloHome extends javax.ejb.EJBHome
{    Hello create() throws java.rmi.RemoteException,
        javax.ejb.CreateException;
}// BEAN CLASS: HelloBean.class
import javax.ejb.*;public class HelloBean implements javax.ejb.SessionBean
{    private SessionContext ctx;public void ejbCreate()
{
        System.out.println("ejbCreate()");
    }public void ejbRemove()
{
        System.out.println("ejbRemove()");
    }public void ejbActivate()
{
        System.out.println("ejbActivate()");
    }public void ejbPassivate()
{
        System.out.println("ejbPassivate()");
    }public void setSessionContext(javax.ejb.SessionContext ctx)
{
        this.ctx = ctx;
    }public String hello()
{
        System.out.println("hello()");
        return "Hello, World!";
    }
}

解决方案 »

  1.   

    //测试客户端import javax.naming.Context;
    import javax.naming.InitialContext;public class TestHello
    { public static void main(String[] args) throws Exception
    {
                   
    Context ctx = new InitialContext(); Object obj = ctx.lookup("Hello"); HelloHome home = (HelloHome)
    javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);
    Hello hello = home.create();
    System.out.println(hello.hello());
    hello.remove();
    }
    }