java RMI注册对象异常?

//helloServer.java
public interface HelloServer extends Remote
{
    public String echo(String msg) throws RemoteException ;
    public Date getTime() throws RemoteException ;
}

//HelloServiceImpl.java
public class HelloServiceImpl extends UnicastRemoteObject implements HelloServer
{
    private String name ;

    public HelloServiceImpl(String name) throws RemoteException
    {
        this.name = name ;
    }

    public String echo(String msg) throws RemoteException
    {
        System.out.println(name + ":调用echo()方法") ;
        return "echo: " + msg + " from " + name ;
    }

    public Date getTime() throws RemoteException
    {
        System.out.println(name + ":调用getTime()方法") ;
        return new Date() ;
    }
}

//SimpleServer.java
public class SimpleServer
{

    public static void main(String[] args) throws Exception
    {
        HelloServer service1 = new HelloServiceImpl("service1") ;
        HelloServer service2 = new HelloServiceImpl("service2") ;

        Context namingContext = new InitialContext() ;
        namingContext.rebind("rmi://localhost:1099/HelloService1" , service1) ;
        namingContext.rebind("rmi://localhost:1099/HelloService2" , service2) ;

        namingContext.rebind("rmi://10.10.160.16:1099/HelloService1" , service1) ;
        namingContext.rebind("rmi://10.10.160.16:1099/HelloService2" , service2) ;

        namingContext.rebind("rmi:HelloService1" , service1) ;
        namingContext.rebind("rmi:HelloService2" , service2) ;

        System.out.println("服务器注册了两个HelloService对象") ;
    }
}

图像是 1.png
运行simpleServer.java报错,而且这三种方式都会报错, 如何解决呢?
报错似乎说是HelloServer类未找到, 但是不明白为什么会出现这种情况, 而且该怎么解决呢?

阅读 2.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
101 新手上路
子站问答
访问
宣传栏