【发布时间】:2014-12-27 20:46:08
【问题描述】:
操作系统:Windows 7
JDK:1.8.0_05
我正在学习一些简单的 RMI 教程,包括 Oracle 的“计算”示例 (compute)。启动我的服务器不需要代码库,并且对与此类似的问题的回答说“代码库是可选的”。但是我的服务器无法注册远程对象,除非它的接口在某个代码库中。
我确保我的 Compute 接口可用于在 localhost 上运行的 Web 服务器,像这样启动注册表服务器:
set CLASSPATH=
rmiregistry -J-Djava.rmi.server.codebase="http://localhost:80/"
一切正常:
Exporting stub
Locating registry
Binding stub
ComputeEngine bound
但是,如果我从 Web 服务器的路径中删除 Compute.class,我会得到一个 ClassNotFoundException:
Exporting stub
Locating registry
Binding stub
java.rmi.ServerException: RemoteException occurred ...:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: edu.uweo.java2.rmi.compute.server.Compute
我可以从 Web 服务器日志中看到尝试下载 Compute.class:
GET '/edu/uweo/java2/rmi/compute/server/Compute.class'
我还尝试在不指定代码库的情况下启动注册表服务器:
set CLASSPATH=
rmiregistry
当我这样做时,没有人会尝试联系我的 Web 服务器(这并不让我感到惊讶),但我仍然会收到 ClassNotFoundException。
我的代码直接来自 Oracle 的教程,其中包含一些额外的打印诊断:
try
{
String name = "Compute";
ComputeEngine engine = new ComputeEngine();
System.out.println( "Exporting stub" );
Compute stub =
(Compute)UnicastRemoteObject.exportObject( engine, 0 );
System.out.println( "Locating registry " );
Registry registry = LocateRegistry.getRegistry();
System.out.println( "Binding stub" );
registry.rebind( name, stub );
System.out.println( "ComputeEngine bound" );
}
谁能告诉我我错过了什么?
谢谢。
【问题讨论】: