在尝试写RMI程序时,如果没有指定RMI的Codebase,程序执行注册的bind或rebind方法时,会报ClassNotFoundException错:
假设设要运行程序为“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路径必需以“/”结尾。
参考:
本文介绍了在编写RMI程序时未指定Codebase导致的ClassNotFoundException问题及其解决方案。通过正确设置Classpath和Codebase路径,可以避免远程调用时找不到类的问题。
2434

被折叠的 条评论
为什么被折叠?



