Reputation: 2666
I'm experimenting with RMI lately and found out that I seem to be unable to send a serialized object if the class file isn't also stored at the webserver. Does this mean that all my serializable classes need to be put in the webservers classpath?
Doesn't really seem like the best design to me IMHO.
Upvotes: 1
Views: 1436
Reputation: 310916
No. All these answers are wrong.
The classes don't need to exist at both sides if you use the RMI codebase feature. You can set up a Web server to host the JAR files and set -Djava.rmi.server.codebase= to define where those classes are available as a list of URLs of those JAR files. You set that at either the server or the client or both depending on who is going to be sending classes that the other side doesn't have. Then RMI annotates those classes with those URLs so the target knows where to get them, and downloads them as needed.
Upvotes: 3
Reputation: 2772
Yes, the class file must exist on the webserver as well, as RMI was intended (way back when) to send an instance of a class across the wire. If you are simply looking to send data to a web server without any encapsulating class business behavior, then there are much newer and simpler ways (JSON, XML, SOAP, etc) to simply send data.
Upvotes: 0