Wednesday, January 11, 2006

Java RMI Headaches

Things one needs to do to get RMI working:

- Everything on the server must be interfaced where where interface extends Remote
- Everything that is passed between server and client must implement Serializable
- Every remote method must throw RemoteException

- You must run rmiregistry.exe on the server
- you cant use LocateRegistry on remote, must use Naming
- If you get a ClassNotFoundException on server it means you havent set your codebase properly.
- Since i havent figured out how to do SecurityManager stuff properly, i can override 2 checkPermission methods in SecurityManager with empty method bodies, thats a quick and dirty fix.
- Alternativly, you can set your policy file located in /lib/security/java.policy to: http://java.sun.com/docs/books/tutorial/rmi/example-1dot2/java.policy

RMI codebase crap:
Apperantly this needs to be set to something all clients can access, so a url on the www must be what this needs.

1. first you must compile your classes into stubs and skelletons with rmic.
- add rmic to your PATH variable in windows so you can use it. reopen all shells!
- or if windows decides to be gay and STILL NOT WORK, move the file to C:\windows
- at this point you should run rmic on your classes, so:
>rmic package/subpackage/ClassName

i get this error:
java.lang.NoClassDefFoundError

Google recomends:
Sometimes the rmic compiler has problems when the runtime libraries aren't
specified in the classpath. You shouldn't have to do this, but for some
reason it works. Try the following:

rmic -classpath ;\jre\lib\rt.jar

ex: rmic -classpath C:\MyClasses;C:\java\jre\lib\rt.jar MyRMIObject

----
did that, still no go. Found this tho:
- eclipse RMI plugin that supports automatic stub/skel generation
http://www.genady.net/rmi/
example:

No comments:

Post a Comment