不断接收java.lang.ClassNotFoundException



我对Java和RMI系统非常陌生。我正在学习一个教程,但我不确定为什么我会不断出现以下错误[1][1] :https://i.stack.imgur.com/xeYTn.png我已经附上了代码(直接取自这里的教程:https://docs.oracle.com/javase/1.5.0/docs/guide/rmi/hello/hello-world.html)

我试过:

  • 删除带有"package"的任何行
  • 更改类路径变量
  • 重新安装java和javac
  • 在"rmiregistry&"中设置类路径命令

如有任何帮助,将不胜感激

编辑:忘记附加代码。Hello.java

import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}

Client.java

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Client {
private Client() {
}
public static void main(String[] args) {
String host = (args.length < 1) ? null : args[0];
try {
Registry registry = LocateRegistry.getRegistry(host);
Hello stub = (Hello) registry.lookup("Hello");
String response = stub.sayHello();
System.out.println("response: " + response);
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
}

Server.java

import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class Server implements Hello {
public Server() {
}
public String sayHello() {
return "Hello, world!";
}
public static void main(String args[]) {
try {
Server obj = new Server();
Hello stub = (Hello) UnicastRemoteObject.exportObject((Remote) obj, 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind("Hello", stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}

您必须运行命令rmiregistry&将代码编译到文件夹中。在这种情况下;文件";

";开始";教程并没有提到这一点。

相关内容

  • 没有找到相关文章

最新更新