java - 在命令行和 Eclipse 中运行 RMI 服务器

标签 java eclipse rmi

我需要使用命令行运行我的 RMI 服务器 RmiEncodingServer), 我的类文件位于此文件夹中:

C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerClasses

在包hw2.rmi.server中。 代码库位于此文件夹中:

C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerCodeBase

在包hw2.rmi.server中。

我使用命令行:

java –classpath C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerClasses\ -Djava.rmi.server.codebase=file:/C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerCodeBase -Djava.security.policy=C:\workspace\distributedhw2\permissions.policy hw2.rmi.server.RmiEncodingServer

但我收到“未找到类”异常,如下所示:

Exception in thread "main" java.lang.NoClassDefFoundError: ûclasspath
Caused by: java.lang.ClassNotFoundException: ûclasspath
        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 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: GÇôclasspath.  Program will exit.

我哪里出错了?

此外,如果您可以提供有关如何在 Eclipse 中运行服务器的说明,我添加了以下内容作为 VM 参数,但我得到了 RmiServerCodeBase 中的类的未找到类异常:

-Djava.security.policy=C:\workspace\distributedhw2\permissions.policy -Djava.rmi.server.codebase=file:/C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerCodeBase

谢谢

最佳答案

我发现问题是我试图引用代码库中的 .java 文件而不是 .class 文件,我认为属性名称“代码库”有点误导。因此,如果您想在 RMI 服务器中执行此操作,可以这样做:

String codeBasePath =  "file:/C:/workspace/distributedhw2/"
        + "AgencyServers/RmiEncodingServer/RmiServerClasses/";
        System.setProperty("java.rmi.server.codebase",codeBasePath);

或者简单地传递以下内容作为 VM 参数:

-Djava.security.policy=C:\workspace\distributedhw2\permissions.policy -Djava.rmi.server.codebase=file:/C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerClasses

关于java - 在命令行和 Eclipse 中运行 RMI 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2979146/

相关文章:

java - RMI 和 Web 服务都使用套接字连接吗?

java - 如何在 Java 中实现 Marshalling 类?

java - 获取 YAML 路径下的所有节点

java - Eclipse中的多IDE调试

osgi - 适合 ERP 等应用程序的框架

java - 为什么参数在 Eclipse 中不起作用?

java - 在另一个包的 main 中使用一个包中的 java 类(同一项目)

java - 是什么让 SSMS 中的 CyanogenMod 允许堆转储,无论其调试标志如何?

java - 我们可以在单个断言中使用多个 TestNG 断言吗

java - 未调用特定于类的渲染器组件