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类未找到, 但是不明白为什么会出现这种情况, 而且该怎么解决呢?

以上是 java RMI注册对象异常? 的全部内容, 来源链接: utcz.com/p/176039.html

回到顶部