解决RMI服务路径查找问题

 

      在尝试写RMI程序时,如果没有指定RMI的Codebase,程序执行注册的bind或rebind方法时,会报ClassNotFoundException错:

 

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: example.hello.Hello java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: example.hello.Hello at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396)

     假设设要运行程序为“example.hello.Server”,解决方法如下:

    java -classpath classDir -Djava.rmi.server.codebase=file:classDir/ example.hello.Server

     例如,使用Windows操作系统,要运行的类文件放在“e:/test/”目录,写法如下:

    java -classpath "e:/test/" -Djava.rmi.server.codebase=file:///e:/test/ example.hello.Server

 

注意:codebase路径必需以“/”结尾。

 

参考:

    Dynamic code downloading using Java RMI

你可能感兴趣的:(java,thread,exception,server,File,nested)