如何设置rmiregistry使用的类路径? [英] How do I set the classpath that rmiregistry uses?

查看:150
本文介绍了如何设置rmiregistry使用的类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作Java RMI客户端/服务器应用程序。我在启动应用程序的服务器端时遇到问题,因为当我尝试启动服务器端时,它在调用Registry.bind()方法期间一直运行到 ClassNotFoundException 应用程序。

I'm trying to make a Java RMI client/server app. I'm running into problems starting up the server side of my app, as it keeps running into a ClassNotFoundException during the call to the Registry.bind() method when I attempt to start up the server side of the app.

我从这里的简单教程开始: http://docs.oracle.com/javase/1.5.0/docs/guide/rmi/hello/hello-world.html 。按照这些说明操作后,它最初抛出一个ClassNotFoundException,抱怨它找不到example.hello.Hello。我能够通过从教程中的 destDir 目录启动rmiregistry来解决这个问题,因为rmiregistry显然使用它的初始起始目录作为其类路径的一部分。

I started with the simple tutorial here: http://docs.oracle.com/javase/1.5.0/docs/guide/rmi/hello/hello-world.html. After following those instructions, it was initially throwing a ClassNotFoundException complaining that it couldn't find "example.hello.Hello". I was able to resolve that by starting the rmiregistry FROM the destDir directory in the tutorial, since rmiregistry, apparently, uses its initial starting directory as part of its classpath.

之后我开始使用我的其他测试应用程序,直到我开始在服务器类中使用第三方jar文件时,我一直很好。现在,如果我的服务器类引用任何jar文件中的任何内容,则Registry.bind()会抛出ClassNotFoundException,因为rmiregistry应用程序不知道这些jar文件。

I started on my other test app after that, and I was fine until I started to use third-party jar files in my server class. Now Registry.bind() throws a ClassNotFoundException if my server class references anything in any jar file since the rmiregistry app doesn't know about those jar files.

至于我可以说,rmiregistry不接受任何类型的路径启动arg,所以我想知道我怎么能告诉它我想要它承认什么类路径。根据这里的教程: http://docs.oracle.com/javase/tutorial /rmi/running.html ,您必须确保运行rmiregistry的shell或窗口具有 no CLASSPATH环境变量集或已设置一个CLASSPATH环境变量,它不包含要下载到远程对象客户端的任何类的路径。这听起来与我需要的相反......或者我读错了吗?有没有人有任何成功启动使用第三方jar的RMI客户端/服务器(在我的情况下是commons-io,commons-logging和rmiio)?

As far as I can tell, rmiregistry does not accept any sort of classpath startup arg, so I'm wondering how I can tell it what classpath I want it to acknowledge. According to the tutorial here: http://docs.oracle.com/javase/tutorial/rmi/running.html, "you must make sure that the shell or window in which you will run rmiregistry either has no CLASSPATH environment variable set or has a CLASSPATH environment variable that does not include the path to any classes that you want downloaded to clients of your remote objects." That sounds like the opposite of what I need... or am I reading it incorrectly? Has anyone had any success starting up a RMI client/server that uses third-party jars (commons-io, commons-logging, and rmiio, in my case)?

这是在Windows上,他们的方式。

This is on Windows, by they way.



更新
我找到了解决方法。请参阅下面的答案。


Update I found a way around it. See my answer below.

推荐答案

(我最初发布此答案是对我的问题的更新.Per Zecas的建议在其中一个评论,我正在将其移至答案部分。)

(I had originally posted this answer as an update to my question. Per Zecas's suggestion in one of the comments, I'm moving it to the answer section.)

我能够通过违反第二篇教程中引用的建议来启动服务器部分我的上述问题:

I was able to get the server part to start up by disobeying the suggestion in the second tutorial referenced in my question above:


你必须确保你将运行
rmiregistry的shell或窗口 CLASSPATH环境变量集或
有一个CLASSPATH环境变量,该变量不包含要下载到远程$客户端的任何类的
的路径b $ b对象。

"you must make sure that the shell or window in which you will run rmiregistry either has no CLASSPATH environment variable set or has a CLASSPATH environment variable that does not include the path to any classes that you want downloaded to clients of your remote objects."

我创建了一个CLASSPATH环境变量并添加了我的.class输出目录和每个第三方jar文件到那。我以为我之前尝试过,但我猜不是......只是想我会留下我的解决方案以防其他人遇到同样的问题。

I created a CLASSPATH environment variable and added my .class output directory and each of the third-party jar files to that. I thought I had tried that before, but I guess not... Just thought I'd leave my solution in case someone else has the same problem.

这篇关于如何设置rmiregistry使用的类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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