RMI 连接错误客户端

发布于 2024-10-03 12:11:20 字数 2283 浏览 2 评论 0原文

我在尝试连接到 RMI 服务时收到错误:

我正在使用以下方式执行客户端代码:

java -Djava.security.manager -Djava.security.policy=path\to\policy.all -jar "path\to\jarfile" "localhost:2020"

我正在使用的代码是:

public class PowerServiceClient
{
    public static void main(String args[]) throws Exception
    {

         System.setSecurityManager
            (new RMISecurityManager());

         // Call registry for PowerService
         PowerService service = (PowerService) Naming.lookup
            ("rmi://localhost:2020/PowerService");

         DataInputStream din = new
             DataInputStream (System.in);

    }
}

我收到的错误是:

    Exception in thread "main" java.rmi.UnmarshalException: 
    error unmarshalling return; nested exception is:

    java.lang.ClassNotFoundException: rmiservice.PowerService
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Unknown Source)
    at powerclient.PowerServiceClient.main(PowerServiceClient.java:32)
    Caused by: java.lang.ClassNotFoundException: rmiservice.PowerService
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at sun.rmi.server.LoaderHandler.loadProxyInterfaces(Unknown Source)
    at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
    at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
    at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
    at java.rmi.server.RMIClassLoader.loadProxyClass(Unknown Source)
    at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
    at java.io.ObjectInputStream.readProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    ... 3 more

有人知道这里的问题是什么吗?

I am getting an error when attempting to connect to an RMI service:

I am executing the client code using:

java -Djava.security.manager -Djava.security.policy=path\to\policy.all -jar "path\to\jarfile" "localhost:2020"

The code I am using is:

public class PowerServiceClient
{
    public static void main(String args[]) throws Exception
    {

         System.setSecurityManager
            (new RMISecurityManager());

         // Call registry for PowerService
         PowerService service = (PowerService) Naming.lookup
            ("rmi://localhost:2020/PowerService");

         DataInputStream din = new
             DataInputStream (System.in);

    }
}

The error I am receiving is:

    Exception in thread "main" java.rmi.UnmarshalException: 
    error unmarshalling return; nested exception is:

    java.lang.ClassNotFoundException: rmiservice.PowerService
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Unknown Source)
    at powerclient.PowerServiceClient.main(PowerServiceClient.java:32)
    Caused by: java.lang.ClassNotFoundException: rmiservice.PowerService
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at sun.rmi.server.LoaderHandler.loadProxyInterfaces(Unknown Source)
    at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
    at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
    at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
    at java.rmi.server.RMIClassLoader.loadProxyClass(Unknown Source)
    at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
    at java.io.ObjectInputStream.readProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    ... 3 more

Does anyone know what the problem is here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一笔一画续写前缘 2024-10-10 12:11:20

注册表需要访问您的远程接口类及其对其类路径的依赖项。对此有三种解决方案。为了方便起见:

  1. 使用 LocateRegistry.createRegistry() 在服务器 JVM 内启动注册表
  2. 使用 -D-Jclasspath= 参数启动 rmiregistry 进程
  3. 使用代码库功能。

The Registry needs access to your remote interface class and its dependencies on its classpath. There are three solutions to that. In order of ease:

  1. Start the Registry inside your server JVM, with LocateRegistry.createRegistry()
  2. Start the rmiregistry process with a -D-Jclasspath= argument
  3. Use the codebase feature.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文