RMI: Using a foreign remote object

203 Views Asked by At

Just when I thought I know how RMI works, it comes back and tell me I do not. The following situation:

I have given:

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

2

There are 2 best solutions below

2
On

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).

0
On

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.