开发者

Problems downloading the Stub class from server to Client - Java RMI

I am having problems with running my HelloWorld Java RMI application. I have the server, remote class and remote interface in one computer and a client and a remote interface in another. The server and registry run fine. When I try to run the client, i receive this error:

Client1 exception: java.rmi.UnmarshalException: error unmarshalling return; nested exception is: java.lang.ClassNotFoundException: Remote_Stub (no security manager: RMI class loader disabled)

I noticed that if I have the Remote_Stub.class file in the same directory as the client, everyth开发者_高级运维ing works fine. So i figured that my problem is downloading the stub from the server to the client.

I am not quite sure why this is giving me this error or not, but after doing some research I think it has something to do with security as in I dont have permission to download the file from one computer to the other (because it states "no security manager") If that is so, does anyone know how I could solve this problem? Or how I could set the permission?

Thanks!! Micheal


Your server needs to set a security policy. You need a JVM property like:

-Djava.security.policy=/path/to/myserver.policy

Where myserver.policy is a file that has your server's security policies, for example:

grant {  
    permission java.security.AllPermission "", "";  
};

On a related note, I am not personally a huge fan of RMI because it's given me greif in the past with the way it deals with class versioning between server and clients, and the fact that it's Java specific, so limits your clients to being written in Java. If you have the flexibility to choose a different client-server technology, you should take a look at SOAP (AXIS2 is not bad) or REST services (Restlet looks pretty promising). This post may help you with pros and cons:

http://michaeldehaan.net/2008/07/17/xmlrpc-vs-rest-vs-soap-vs-all-your-rpc-options/


http://download.oracle.com/javase/tutorial/rmi/client.html

Take a look at that. It states clearly how you instantiate a SecurityManager in your client as the first step to make sure the stubs are downloaded.


You don't need stubs at all from JDK 1.5. See the class Javadoc for UnicastRemoteObject.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜