运行示例RMI应用程序 [英] Running a sample RMI application

查看:72
本文介绍了运行示例RMI应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行Oracle网站http://docs.oracle.com/javase/tutorial/rmi/running.html .但是,尝试同时在Eclipse和命令行中运行时,我无法运行服务器或客户端.实际上,在Eclipse中运行时会出现此错误:

I am trying to run the example of the RMI application given in the Oracle website http://docs.oracle.com/javase/tutorial/rmi/running.html. However, trying both Eclipse and in the command line, I can't run the server nor the client. In fact, when running in Eclipse I get this error:

ComputeEngine exception:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")

我还这样更改了VM参数:

I also have changed the VM Argument like this:

  • 对于ComputeEngine(服务器):

  • For the ComputeEngine (server):

-Djava.security.manager -Djava.rmi.server.codebase = file:/用户/名称/文档/工作区/PiComputationRM/src/compute/compute.jar -Djava.security.policy =/用户/名称/Documents/workspace/PiComputationRM/server.policy

-Djava.security.manager -Djava.rmi.server.codebase=file:/Users/name/Documents/workspace/PiComputationRM/src/compute/compute.jar -Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/server.policy

对于ComputePi(客户端):

For the ComputePi (client):

-Djava.security.policy =/用户/名称/文档/工作区/PiComputationRM/client.policy

-Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/client.policy

我的客户端和服务器策略的内容是:

The content of my client and server policy is:

grant {
permission java.security.AllPermission;
};

此外,当我尝试在终端中使用以下命令运行服务器时:

Also when I try to run the server in terminal with:

java -Djava.security.policy="server.policy" src/engine/ComputeEngine.java

我收到此错误:

Error: Could not find or load main class src.engine.ComputeEngine.java

请提供任何帮助,我在互联网上度过了很多时间?

Please any help, I have spent many hours on the Internet in vain ??

推荐答案

ComputeEngine exception:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")

您正在使用安全管理器,但尚未在.policy文件中授予该权限.

You are using a security manager and you haven't granted that permission in your .policy file.

我还这样更改了VM参数:

I also have changed the VM Argument like this:

对于ComputeEngine(服务器):

For the ComputeEngine (server):

-Djava.security.manager -Djava.rmi.server.codebase=file:/Users/name/Documents/workspace/PiComputationRM/src/compute/compute.jar -Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/server.policy

那里有几个问题:

  • 一个文件:除非代码库指定一个共享位置,该名称对于客户端和注册表是可见的,否则它将无法正常工作.这看起来不像其中之一.

  • a file: codebase isn't going to work unless it specifies a shared location that is visible by that name to the client and the Registry. This doesn't look like one of those.

您需要检查该名称是否为策略文件的正确名称

you need to check whether that is the correct name for the policy file

您甚至不需要服务器中的安全管理器或策略,除非客户端设置了自己的代码库并打算为您提供类.在此示例中不会发生这种情况.

you don't even need a security manager or policy in the server, unless the client is setting its own codebase and is going to provide classes to you. That doesn't happen in this example.

对于ComputePi(客户端):

For the ComputePi (client):

-Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/client.policy

再次检查此名称.

此外,当我尝试在终端中使用以下命令运行服务器时:

Also when I try to run the server in terminal with:

java -Djava.security.policy="server.policy" src/engine/ComputeEngine.java

我收到此错误:

Error: Could not find or load main class src.engine.ComputeEngine.java

当然可以.您向JVM提供了一个编译器命令.使用教程中提供的命令.您不会将.java文件命名为JVM.

Of course you did. You gave a compiler command to the JVM. Use the command provided in the tutorial. You don't name .java files to the JVM.

我花了很多时间徒劳地上网了

I have spent many hours on the Internet in vain

您应该已经根据教程仔细检查了您的工作.您至少在两个地方误读了本教程.

You should have been double-checking your work against the tutorial instead. You've misread the tutorial in at least two places.

我还要质疑您是否真的需要代码库功能.我首先将其删除,然后将安全管理器全部删除,然后在没有他们的情况下使其正常工作.对于第一个RMI项目来说,这太复杂了.

I would also question whether you really need the codebase feature at all. I would start by removing it, and the security managers, altogether, and just get it working without them. It's too much of a complication for a first RMI project.

这篇关于运行示例RMI应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆