【问题标题】:Unable to start rmi server when codebase used使用代码库时无法启动 rmi 服务器
【发布时间】:2016-10-23 12:32:17
【问题描述】:
    CalculationServerRegistrationService server = new CalculationServerRegistrationService();
    ICalculationServerRegistrationService stub  = (ICalculationServerRegistrationService) UnicastRemoteObject.exportObject(server, RMI_PORT);
    // Bind the remote object's stub in the registry
    Registry registry = LocateRegistry.getRegistry();
    registry.bind("ICalculationServerRegistrationService", stub);
    new RMIServerTimeoutChecker().run();
}

当我在没有参数但在 D:/git/nnCloud/BE/nnCloudRESTService/target/classes 文件夹中的同一台机器上启动 rmiregistry 命令时,一切正常。但是,由于我需要来自不同程序的两台服务器,我希望拥有一个带有两个代码库的 rmiregistry,因此需要明确指定它,而不是在不同的目录中运行两个“rmiregistry”命令。

我看到的唯一解决方案是运行

rmiregistry -J-Djava.rmi.server.codebase="file:/D:/git/nnCloud/BE/nnCloudRESTService/target/classes 文件:/D:/git/nnCloud/BE/nnCloudRESTService/target/classes "

这样做后,我的应用程序在 registry.bind 处崩溃。

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: com.mycompany.nncloudrestservice.serverservice.ICalculationServerRegistrationService

【问题讨论】:

  • 你有一个 ClassNotFoundException;这很可能意味着在您的一种设置中,classpath 不是应有的样子。

标签: java windows rmi


【解决方案1】:

代码库不会告诉当前的 JVM 在哪里可以找到类。 CLASSPATH 就是这样做的。代码库告诉下游 JVM 在哪里可以找到类。

此处正确的解决方案是使用适当的java.rmi.server.codebase 参数运行每个导出和绑定远程对象的JVM。不是注册表。

【讨论】:

  • 为 jvm 设置 -Djava.rmi.server.codebase 也不起作用。
  • 为服务器 JVM 设置它?为我工作。
【解决方案2】:

从代码运行rmiregistry后没有问题,放置LocateRegistry.createRegistry后

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-06
    • 1970-01-01
    相关资源
    最近更新 更多