我在这里关注分布式系统的基本 Java RMI 教程:http: //people.cs.aau.dk/~bnielsen/DS-E08/Java-RMI-Tutorial/
我在编译我的服务器实现时遇到问题。
错误如下:
RMIServer.java:5: cannot find symbol
symbol: class ServerInterface
public class RMIServer extends UnicastRemoteObject implements ServerInterface {
^
1 error
这是我的服务器实现:
package rmiTutorial;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.*;
public class RMIServer extends UnicastRemoteObject implements ServerInterface {
private String myString = " ";
//Default constructor
public RMIServer() throws RemoteException {
super();
}
//inherited methods
public void setString(String s) throws RemoteException {
this.myString =s;
}
public String getString() throws RemoteException{
return myString;
}
//main: instantiate and register server object
public static void main(String args[]){
try{
String name = "RMIServer";
System.out.println("Registering as: \"" + name + "\"");
RMIServer serverObject = new RMIServer();
Naming.rebind(name, serverObject);
System.out.println(name + " ready...");
} catch (Exception registryEx){
System.out.println(registryEx);
}
}
}
服务器接口:
package rmiTutorial;
import java.rmi.*;
public interface ServerInterface {
public String getString() throws RemoteException;
public void setString(String s) throws RemoteException;
}
RMIServer 类和 ServerInterface 都在同一个包中。我完全按照教程进行了操作,所以我真的不明白我是如何设法打破它的!
任何帮助将不胜感激!谢谢。
托里