Hi all.
I'm tearing my hear off here. Production is standing still because I can't get the bloody RMI working.
First of all, the premise of the task - I'm running:
- Mac OSX 10.5.8
- Java 1.6
- Netbeans IDE 6.7
And I'm trying to complete the [SUN RMI Tutorial |http://java.sun.com/docs/books/tutorial/rmi/].
What I want to do is compile and run from netbeans, which should be possible, right?
What I have:
My files:
/Users/Jonas/Documents/workspace/RMI/src/client/ComputePi.java
/Users/Jonas/Documents/workspace/RMI/src/client/Pi.java
/Users/Jonas/Documents/workspace/RMI/src/compute/Compute.java
/Users/Jonas/Documents/workspace/RMI/src/compute/Task.java
/Users/Jonas/Documents/workspace/RMI/src/engine/ComputeEngine.java
/Users/Jonas/Documents/workspace/RMI/src/client.policy
/Users/Jonas/Documents/workspace/RMI/src/server.policy
When I try to run the project I get the following error:
run:
ComputeEngine exception:
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
at java.net.Socket.connect(Socket.java:513)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:180)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at engine.ComputeEngine.main(ComputeEngine.java:33)
Contents of server.policy:
grant codeBase "file:/Users/Jonas/Documents/workspace/RMI/src/" {
permission java.security.AllPermission;
};
Contents of ComputeEngine.java:
package engine;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import compute.Compute;
import compute.Task;
public class ComputeEngine implements Compute {
public ComputeEngine() {
super();
}
public <T> T executeTask(Task<T> t) {
return t.execute();
}
public static void main(String[] args) {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
String name = "Compute";
Compute engine = new ComputeEngine();
Compute stub =
(Compute) UnicastRemoteObject.exportObject(engine, 0);
Registry registry = LocateRegistry.getRegistry();
registry.rebind(name, stub);
System.out.println("ComputeEngine bound");
} catch (Exception e) {
System.err.println("ComputeEngine exception:");
e.printStackTrace();
}
}
}
I suppose it's a problem with including the server.policy. I've tried to include it as an argument:
-Djava.security.policy=/Users/Jonas/Documents/workspace/RMI/src/server.policy
With the same result though.
Is it really that difficult to do RMI programming?
I would really appreciate any help!
Thanks in advance.