我試圖得到一個RMI連接下去。我遇到了很多安全問題,但一直無法找到解決辦法。我執行我的jar文件有:RMI連接被拒絕
java -Djava.security.policy=java.security.AllPermission -jar "myjarfile"
的代碼,我一直用它來創建此就是:
public class server
{
public static void main(String args[])throws Exception
{
if (System.getSecurityManager() == null)
System.setSecurityManager (new RMISecurityManager() {
public void checkConnect (String host, int port) {}
public void checkConnect (String host, int port, Object context) {}
});
try
{
sampleserverimpl server = new sampleserverimpl();
System.out.println("SERVER IS WAITING");
LocateRegistry.createRegistry(2020);
//Runtime.getRuntime().exec("rmiregistry 2020");
Naming.rebind("//localhost:2020/SERVER", server);
}
catch(Exception e)
{
System.out.println(e);
}
}
};
我收到的錯誤跟蹤:
Exception in thread "RMI TCP Connection(idle)" java.security.AccessControlExcept
ion: access denied (java.net.SocketPermission 127.0.0.1:31199 accept,resolve)jav
a.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
java.io.EOFException
我曾嘗試不同的方式來解決這個問題,任何人都可以在這裏看到問題嗎?
謝謝
現在運行,謝謝。試用過這個文件,但沒有添加到安全管理器中。 +1 – chrissygormley 2010-11-18 12:26:51