Java Remote Method Invocation (RMI) |
1. Preface
2. The system RMIThe mechanism is as follows:
3. The steps to set the system
4. Example 1 Regards AppletThe related casses are the following: Regards.java RegardsImpl.java RegardsApplet.java 1.First prompt: set CLASSPATH = ”C:\J2EE\RMI\Regards" Compile: C:\J2EE\RMI\Regards> javac Regards.java C:\J2EE\RMI\Regards> javac RegardsImpl.java C:\J2EE\RMI\Regards> javac RegardsApplet.java Run: C:\J2EE\RMI\Regards> start rmiregistry C:\J2EE\RMI\Regards> java -Djava.security.policy=policy.all rmiServerImpl 2.Second prompt: set CLASSPATH = ”C:\J2EE\RMI\Regards" C:\J2EE\RMI\Regards> Appletviewer RegardsApplet The related applet is: RegardsApplet 5. Example 2 Remote calculusThe related casses are the following: rmiServer.java rmiServerImpl.java rmiClient.java 1.First prompt: set CLASSPATH = ”C:\J2EE\RMI\Operation" Compile: C:\J2EE\RMI\Operation> javac rmiServer.java C:\J2EE\RMI\Operation> javac rmiServerImpl.java C:\J2EE\RMI\Operation> rmic rmiServerImpl C:\J2EE\RMI\Operation> javac rmiClient.java Run: C:\J2EE\RMI\Operation> start rmiregistry C:\J2EE\RMI\Operation> java -Djava.security.policy=policy.all rmiServerImpl 2.Second prompt: set CLASSPATH = ”C:\J2EE\RMI\Operation" C:\J2EE\RMI\Operation> java -Djava.security.policy=policy.all rmiClient The rmic compiler has generated rmiServerImpl_Stub.class. The Java -D 6. About Security policyIn a such file, we can allow are deny access to some directories. In These two programs, we have used the policy.allto grant some necessary access. We can also the Java\bin directory (as C:\Program Files\Java\jdk1.6.0_03\bin) and policytool.exe. If we give all permissions, the file we can save looks like this:
/* AUTOMATICALLY GENERATED ON Sun Mar 02 13:26:44 EST 2008*/
/* DO NOT EDIT */
grant {
permission java.security.AllPermission;
};
In the Java lib directory (as C:\Program Files\Java\jre1.5.0_14\lib\security),
we find java.policy file where we can set permissions.
|