java rmi stub cannot be cast to_java RMI java.rmi.StubNotFoundException 错误的解决

在设计小型分布式系统的时候,可以利用java的rmi 接口来方便程序设计。

第一次设计hello world, 可以参考

很好的tutorial

我在linux下跑一个类似的程序,也是server 以及client 两部分。 和简单的helloworld不同的是

server和client之间要有交互,没有问题。

但是在windows以及mac的系统下跑同样的程序,报错 stub class not found

参考

参考1中提及:On a JDK less than 1.5, that is 1.4 or smaller one would

have to do “javac *.java” and then “rmic ServerImplementor.class”

that would produce a file ServerImplementor_Stub.class. This is the

so called Stub file.

参考2 中提及:Many of the examples export services as remote RMI

objects. These objects are subclasses of UnicastRemoteObject. What

gets exported is not the object itself, but a stub that will act as

proxy for the object (which continues to run back in the server).

The stub has to be created using the rmic compiler as in

rmic -v1.2 -d . rmi.FileClassifierImpl

This will create a FileClassifierImpl_Stub.class in the rmi

subdirectory. The stub class file needs to be accessible to the

Java runtime in the same way as the original class file.

参考3中提到 All of the Remote interfaces and classes should be compiled

using javac. Once this has been completed, the stubs and skeletons

for the Remote interfaces should be compiled by using the rmic stub

compiler. The stub and skeleton of the example Remote interface are

compiled with the command:

rmic Hello

也就是说作为stub的部分要通过rmic 命令编译, 于是我利用rmic

rmic server

rmic client

之后再次运行程序,错误解决。

但是为什么我的另一个简单的hello world 程序并没有运行这个部分也可以跑,

参考1中提及: 这是由于使用了UnicastRemoteObject,中的exportObject(Remote obj,

int port) 引起的。可是按照这种说法server和client两端都有entends unicastremoteobject,

应该rmic server和client 才对,可是如果只运行rmic server 仍报错。 如果只运行 rmic client

错误解决。 在我的理解中, server

已经在注册过,但是在交互的情况下,client端也需要注册,这样才能找到彼此。不确定。现在没时间查错。以后来看。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值