我试图得到一个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