我在这里学习分布式系统的基本 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);
}
}
}
服务器接口(interface):
package rmiTutorial;
import java.rmi.*;
public interface ServerInterface {
public String getString() throws RemoteException;
public void setString(String s) throws RemoteException;
}
RMIServer 类和 ServerInterface 都在同一个包中。 我完全按照教程进行操作,所以我真的不明白我是如何成功破解它的!
任何帮助将不胜感激! 谢谢。
托里
最佳答案
我怀疑你是单独编译这些的。本教程对此并不清楚,但您需要将它们一起编译(在最简单的情况下):
javac rmiTutorial/RMIServer.java rmiTutorial/ServerInterface.java
(根据需要包括其他适当的标志 - 库、类路径等)。
您需要将两者一起编译,以便编译器在构建 RMIServer
时可以找到 ServerInterface
。您可以首先编译ServerInterface
,但随后需要使用合适的类路径引用编译RMIServer
,以便它可以找到该接口(interface)。
关于Java RMI 教程编译时错误 - 未找到接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13603605/