public <return-type> methodName( <parameter-list> ) throws java.rmi.RemoteException;
if ( System.getSecurityManager() == null ) { System.setSecurityManager( new java.rmi.RMISecurityManager() ); }
java.rmi.Naming.rebind("HelloServer", obj);obj refers to the constructed remote object server; "HelloServer" illustrates the service reference String.
Hello hello = (Hello) Naming.lookup("//" + machineName + "/HelloServer");
machineName is a String containing either the domain name or the IP address of the machine on whch the server and rmiregistry are running. Naming.lookup can throw various exceptions (see Java API for java.rmi.Naming.lookup): It must be within a try-catch block or the method must include these exceptions in its throws clause.
Compile all the .java files as usual.
An example of a policy file that is sufficient (but dangerously permissive) is:
grant { // Allow everything for now permission java.security.AllPermission; };
Make a codebase for all client classes that the server needs but does not have in its classpath (e.g., classes of Remote method parameters)
For example, the command below runs a Java application called Application. In this case, the system expects the policy file called policy to be in the directory from which the java command executes.
java -Djava.rmi.server.codebase=http://www.cs.ucsb.edu/~cappello/classes/ \ -Djava.security.policy=policy \ Application
I need class files in my public_html/classes directory to be readable by all. The classes directory needs to be readable and executable by all. The trailing slash on the codebase specification is crucial.