This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Running RMI
Posted by Ramesh Vasu on December 03, 2001 at 5:27 PM
Hi Rob, You probably figured out how to run the example by now. I had the very same problem. Two things made the difference for me. 1. I had to set the classpath correctly to point to where my RMI server was BEFORE stating the RMI Registry. 2. Had to specifiy the the policy file on the command line thus: -Djava.security.policy=c:\some_policy_file. Of course, as the other two respondents had indicated, I had to grant permission within the policy file: grant { permission java.security.AllPermission; }; This made the server work for. Hope this helps. Cheers :) -Ramesh > Hi Rob, > If you want to just test the RMI code and see how it functions then you have to comment on the following inside public static void main() and do the usual stuff of compiling and creating stubs and skeletons. > // System.setSecurityManager(new RMISecurityManager()); > > This should help you in understanding the basics about RMI. > To run with the above said code you need to change the policy file. Run the policy tool in the bin directory to grant permissions to the files. > Have a nice time coding .. > robert. > > I've tried to compile and run the RMI sample code of "Thinking in Java" ebook. But I always got exceptions while running server, > > here is the exception traces, anybody can tell me, what's wrong with that. > > Thanks > > Robert > > java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve) > > at java.lang.Throwable.fillInStackTrace(Native Method) > > at java.lang.Throwable.(Throwable.java:94) > > at java.lang.Exception.(Exception.java:42) > > at java.lang.RuntimeException.(RuntimeException.java:47) > > at java.lang.SecurityException.(SecurityException.java:39) > > at java.security.AccessControlException.(AccessControlException.java:57) > > at java.security.AccessControlContext.checkPermission(Compiled Code) > > at java.security.AccessController.checkPermission(Compiled Code) > > at java.lang.SecurityManager.checkPermission(Compiled Code) > > at java.lang.SecurityManager.checkConnect(SecurityManager.java:1021) > > at java.net.Socket.(Socket.java:258) > > at java.net.Socket.(Socket.java:98) > > at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:29) > > at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Compiled Code) > > at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:497) > > at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:194) > > at sun.rmi.transport.tcp.TCPChannel.newConnection(Compiled Code) > > at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322) > > at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source) > > at java.rmi.Naming.rebind(Naming.java:165) > > at PerfectTime.main(PerfectTime.java:19)> > The server code is: > > public class PerfectTime extends UnicastRemoteObject implements PerfectTimeI{ > > public long getPerfectTime() throws RemoteException{ > > return System.currentTimeMillis(); > > } > > public PerfectTime() throws RemoteException{ > > super(); > > } > > public static void main(String[] args){ > > System.setSecurityManager(new RMISecurityManager()); > > try{ > > PerfectTime pt = new PerfectTime(); > > Naming.rebind("PerfectTime", pt); > > System.out.println("Object registered!"); > > }catch(Exception e){ > > e.printStackTrace(); > > } > > } > > }
Replies:
|