RMI: Using a foreign remote object
Just when I thought I know how RMI works, it comes back and tell me I do not. The following situation:
I have given:
- an interface: http://pastebin.com/KxXH1jQ9
- an adress where the rmiregistry is runnung
The interface offers cleary 3 getter methods to gain informations about the object. I simply want to lookup the object call the three methods and print out theirs values:
However the following implementation ( http://pastebin.com/d4JS0Wai ) does not do the trick resulting in the following exception:
Exception in thread "main" java.rmi.UnmarshalException: error unmarshalling return; nested exception is: java.lang.ClassNotFoundException: Article at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source) at rmi.ArticleDisplayer.main(ArticleDisplayer.java:21)
Caused by: java.lang.ClassNotFoundException: Article at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) ...
Also I don't know why I should need a SecurityManager anyway, as my machine is not executing the code. The code is executed on the machine running the rmiregistry. Anyway this is 开发者_如何转开发my policy file: http://pastebin.com/chGEqceA
This problem occurs because you should have the same Article
class accessible by both the client and the source applications.
You can do a Jar
with the common classes used by the 2 modules (client and server) and use it (I generally give the name "commons" to these type of packages).
Okay, the answer to the problem:
The implementation, as well as the interface are inside the default package. I wrote the program inside my own package: rmi
Also the interfaces I downloaded where in the package rmi. As a matter of fact rmi.Article != Article.
精彩评论