0

I am trying to run the example of the RMI application given in the Oracle website http://docs.oracle.com/javase/tutorial/rmi/running.html. However, trying both Eclipse and in the command line, I can't run the server nor the client. In fact, when running in Eclipse I get this error:

ComputeEngine exception:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")

I also have changed the VM Argument like this:

  • For the ComputeEngine (server):

    -Djava.security.manager -Djava.rmi.server.codebase=file:/Users/name/Documents/workspace/PiComputationRM/src/compute/compute.jar -Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/server.policy

  • For the ComputePi (client):

    -Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/client.policy

The content of my client and server policy is:

grant {
permission java.security.AllPermission;
};

Also when I try to run the server in terminal with:

java -Djava.security.policy="server.policy" src/engine/ComputeEngine.java

I got this error:

Error: Could not find or load main class src.engine.ComputeEngine.java

Please any help, I have spent many hours on the Internet in vain ??

Othmane
  • 1,094
  • 2
  • 17
  • 33
  • See the below question already asked: http://stackoverflow.com/questions/2427473/java-rmi-accesscontrolexception-access-denied – mbsingh Sep 28 '14 at 22:45

1 Answers1

0
ComputeEngine exception:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")

You are using a security manager and you haven't granted that permission in your .policy file.

I also have changed the VM Argument like this:

For the ComputeEngine (server):

-Djava.security.manager -Djava.rmi.server.codebase=file:/Users/name/Documents/workspace/PiComputationRM/src/compute/compute.jar -Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/server.policy

Several problems there:

  • a file: codebase isn't going to work unless it specifies a shared location that is visible by that name to the client and the Registry. This doesn't look like one of those.

  • you need to check whether that is the correct name for the policy file

  • you don't even need a security manager or policy in the server, unless the client is setting its own codebase and is going to provide classes to you. That doesn't happen in this example.

For the ComputePi (client):

-Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/client.policy

Double-check this name.

Also when I try to run the server in terminal with:

java -Djava.security.policy="server.policy" src/engine/ComputeEngine.java

I got this error:

Error: Could not find or load main class src.engine.ComputeEngine.java

Of course you did. You gave a compiler command to the JVM. Use the command provided in the tutorial. You don't name .java files to the JVM.

I have spent many hours on the Internet in vain

You should have been double-checking your work against the tutorial instead. You've misread the tutorial in at least two places.

I would also question whether you really need the codebase feature at all. I would start by removing it, and the security managers, altogether, and just get it working without them. It's too much of a complication for a first RMI project.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I don't understand when you say that I haven't granted permissions for the security manager. I did this grant { permission java.security.AllPermission; };.Enough? isn't it ? – Othmane Sep 28 '14 at 23:37
  • It's only enough if that file was actually loaded. That's why I said to double-check the filenames, and that's what the advice about java.security.debug=access,failure seen elsewhere is all about. It tells you what security domain you were in when you got the problem, and what permissions it had, which in turn tells you whether the file was loaded correctly or not. Obviously in your case it wasn't. – user207421 Sep 28 '14 at 23:46
  • NB You said [here](http://stackoverflow.com/questions/26090326/running-a-sample-rmi-application/26090748#26090748) that you had already tried it with java.security.debug, so you should already have this output to examine. You should edit the relevant part of it into your question. – user207421 Sep 28 '14 at 23:53
  • Thank's in fact there was a mispelled directory name in the path, so there is improvement. However as I said before I have java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: compute.Compute – Othmane Sep 29 '14 at 00:12
  • Do you know what may be the source of this exception ? I think it's because of the registry.rebind(name, stub); line in the main code – Othmane Sep 29 '14 at 00:14
  • As predicted. The problem now is that the class mentioned isn't in the CLASSPATH of the RMI Registry. So either you need to reinstate a *correct* codebase, that is usable by the Registry, or run the Registry with an appropriate classpath, or run the Registry in the server JVM via `LocateRegistry.createRegistry().` – user207421 Sep 29 '14 at 04:14