JAVA RMI ClassNotFound

JAVA RMI ClassNotFound,java,rmi,classnotfoundexception,Java,Rmi,Classnotfoundexception,过去几天我一直在尝试启动一个基本的JavaRMI教程服务器 我首先启动命令行并输入以下内容: rmiregistry java -classpath E:\Rmi\src\* -Djava.rmi.server.codebase=file:/E:/RMI/Src/Hello** Server * I have all my *.java, and *.class files under "E:\RMI\SRC" ** I have attempted to use Hello.class, He

过去几天我一直在尝试启动一个基本的JavaRMI教程服务器

我首先启动命令行并输入以下内容:

rmiregistry
java -classpath E:\Rmi\src\* -Djava.rmi.server.codebase=file:/E:/RMI/Src/Hello** Server
* I have all my *.java, and *.class files under "E:\RMI\SRC"
** I have attempted to use Hello.class, Hello.Java, made 'Hello' into a jar file and
** I have even-attempted to leave it blank
试图启动我的服务器。我用Java8编译了它

我得到的例外是:

Server exception: 
java.rmi.ServerException: 
RemoteException occurred in server thread; 
nested exception is: 
java.rmi.UnmarshalException: 
error unmarshalling arguments; 
nested exception is: 
java.lang.ClassNotFoundException: 
Hello java.rmi.ServerException: 
RemoteException occurred in server thread; 
nested exception is: 
java.rmi.UnmarshalException: 
error unmarshalling arguments; 
nested excep tion is: 
java.lang.ClassNotFoundException:
Hello at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:391)
类别定义如下:

Hello.java:

import java.rmi.Remote; 
import java.rmi.RemoteException;  

// Creating Remote interface for our application 
public interface Hello extends Remote {  
   void printMsg() throws RemoteException;  
}
ImplExample.java

// Implementing the remote interface 
public class ImplExample implements Hello {
    // Implementing the interface method 
    public void printMsg() {  
        System.out.println("This is an example RMI program");  
    }  
}
Client.java

    import java.rmi.registry.LocateRegistry; 
    import java.rmi.registry.Registry;  
    public class Client {  
    private Client() {}  
    public static void main(String[] args) {  
       try {  
     // Getting the registry 
        Registry registry = LocateRegistry.getRegistry(null); 

     // Looking up the registry for the remote object 
        Hello stub = (Hello) registry.lookup("Hello"); 

     // Calling the remote method using the obtained object 
        stub.printMsg(); 

     // System.out.println("Remote method invoked"); 
     } 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.RemoteException; 
import java.rmi.server.UnicastRemoteObject; 

public class Server extends ImplExample { 
   public Server() {} 
   public static void main(String args[]) { 
      try { 
         // Instantiating the implementation class 
         ImplExample obj = new ImplExample(); 

         // Exporting the object of implementation class  
         // (here we are exporting the remote object to the stub) 
         Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);  

         // Binding the remote object (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(); 
      } 
   } 
} 
服务器到达“registry.bind(“hello”,stub)”时崩溃。存根不是空的。同样,此时“RMI注册表”已经启动

我非常感谢您的帮助。

在其中组织类的目录的URL 名为子目录的包

所以URL应该指向类的根目录,大致如下:

-Djava.rmi.server.codebase=file://E:/rmi/src


试试看。

忘记添加,服务器在进入“registry.bind(“hello”,stub)”时崩溃。存根不是空的。同样,此时已启动“RMI注册表”。您是否可以在服务器应用程序上启动RMI服务器而不使用外部进程?仍然不起作用,即使将它们添加到包中,将类与源代码分离并运行:java-classpath E:/RMI/classes/-Djava.RMI.server.codebase=file://E:/RMI/classes/example.hello.server,我仍然得到相同的结果,“UnmarshaleException”和“ClassNotFoundException”。-Djava.rmi.server.code:file://必须在rmiregistry启动时添加到rmiregistry中,而不是在java启动时添加到java中,如说明所示,至少在java版本10.0.2中。TBH,如果我通过阅读我的两本RMI书籍的目录来了解我应该开始阅读真正涉及“基础”的书籍,而不是略读“非编码”内容并参考RMIC的书籍,这将是有帮助的。