RMI连接被拒绝
我正在努力获得rmi连接。我遇到了很多安全问题,但一直无法找到解决这一问题的方法。我执行我的jar文件:
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
我尝试了不同的方法来解决这个问题,有人能看到这个问题吗?
谢谢
没有找到相关结果
已邀请:
2 个回复
秃拳割
接受指向策略文件的URL,该策略文件又包含权限。所以你应该:
作为
文件包含的JVM参数:
另外,为了避免代码中存在NULL检查和手动创建
,您可以通过传递JVM开关请求为您的应用程序自动安装SecurityManager:
。 您的最终JVM调用应如下所示:
翰冒绢县