我正在阅读 sun 网站上的教程,尝试使用 RMI。
但是当我尝试启动服务器时,我得到了这个错误:
ComputeEngine exception:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
at java.security.AccessController.checkPermission(AccessController.java:559)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
at java.net.Socket.connect(Socket.java:574)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at engine.ComputeEngine.main(ComputeEngine.java:31)
有人可以建议如何解决这个问题吗?我如何摆脱这个异常,我该如何解决?
这是我得到异常的地方(我在该行的右侧画了箭头):
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();
}
}
}
最后这就是我开始我的程序的方式:
我将在下面留下可能有用的更多相关信息:
这是文件 ~/.server_policy:
grant codeBase "file:/home/jenia/Documents/eclipse/workspace/asti01/bin" {
permission java.security.AllPermission;
};
这是项目目录的树:
/home/jenia/Documents/eclipse/workspace/asti01$ tree
.
├── bin
│ ├── client
│ │ ├── ComputePi.class
│ │ └── Pi.class
│ ├── compute
│ │ ├── Compute.class
│ │ └── Task.class
│ └── engine
│ └── ComputeEngine.class
└── src
├── client
│ ├── ComputePi.java
│ └── Pi.java
├── compute
│ ├── Compute.java
│ └── Task.java
├── compute.jar
└── engine
└── ComputeEngine.java
这是文件夹的树 ~/public_html
/home/jenia/public_html/
└── classes
├── client
│ └── Pi.class
└── compute.jar