为什么简单的RMI服务器需要Codebase? [英] Why Does Simple RMI Server Need Codebase?

查看:158
本文介绍了为什么简单的RMI服务器需要Codebase?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作系统:Windows 7

JDK:1.8.0_05

OS: Windows 7
JDK: 1.8.0_05

我正在处理一些简单的RMI教程,包括Oracle的计算示例( 计算)。启动我的服务器不应该需要代码库,并且类似于这个问题的答案说代码库是可选的。然而,我的服务器无法注册远程对象,除非它的接口位于某个代码库中。

I am working through some simple RMI tutorials including Oracle's "Compute" sample (compute). Starting my server should not require a codebase, and answers to questions similar to this one say that "the codebase is optional." Yet my server can't register a remote object unless its interface is in some codebase.

我确保我的Compute接口可用于在localhost上运行的Web服务器,启动注册表服务器是这样的:

I make sure my Compute interface is available to the web server running on localhost, start the registry server like this:

set CLASSPATH=
rmiregistry -J-Djava.rmi.server.codebase="http://localhost:80/"

一切正常:

Exporting stub
Locating registry 
Binding stub
ComputeEngine bound

但是如果我从Web服务器的路径中删除Compute.class,我会得到一个ClassNotFoundException:

But if I remove Compute.class from the web server's path I get a 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

我可以从网络服务器日志中看到有人试图下载Compute.class:

I can see from the web server log that an attempt was made to download Compute.class:

GET '/edu/uweo/java2/rmi/compute/server/Compute.class'

我也尝试过在没有指定代码库的情况下启动注册表服务器:

I also tried starting the registry server without specifying a codebase:

set CLASSPATH=
rmiregistry

当我这样做时,没有人试图联系我的网络服务器(这并不让我感到惊讶)但我仍然得到ClassNotFoundException。

When I do it this way nobody tries to contact my web server (which doesn't surprise me) but I still get the ClassNotFoundException.

我的代码来自Oracle的教程,其中包含几个额外的打印诊断信息:

My code comes right out of Oracle's tutorial with a couple of extra printed diagnostics thrown in:

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" );
}

谁能告诉我我缺少的东西?

Can anyone tell me what I'm missing?

谢谢。

推荐答案

你是对的,你不需要使用代码库功能。但是,这意味着您的远程接口,它所依赖的类以及存根(如果您正在使用它)必须在其类路径上对客户端和注册表都可用。您获得的异常表明注册表在其CLASSPATH上没有这些类。

You are correct, you don't need to use the codebase feature. However that means that your remote interface, the classes it depends on, and the stub if you're using one must be available to both the client and the Registry on their classpaths. The exception you're getting indicates that the Registry doesn't have these classes on its CLASSPATH.

这篇关于为什么简单的RMI服务器需要Codebase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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