How do I set the classpath that rmiregistry uses?

£可爱£侵袭症+ 提交于 2019-11-28 00:45:23
user207421

The remarks about unsetting the CLASSPATH only apply if you're using the RMI codebase feature, as the cryptic remark about downloading classes is intended to imply.

If you're not using the codebase feature, just either:

  1. Set the CLASSPATH environment variable as required before starting rmiregistry, as shown elsewhere here, or
  2. Start rmiregistry with -J-Djava.class.path=...
  3. Start the Registry inside your server JVM, with LocateRegistry.createRegistry(). This is in many ways the best solution, as it lives and dies with the JVM, shares its classpath, and incidentally complies with the requirements for the codebase feature as well.

If you do (3), you must store the return value into a static variable to prevent it from being garbage-collected, which causes the registry to be unexported, which can lead to DGC of the remote object, which can lead to it being GC'd, which will lead to the listening thread exiting, which can lead to the whole JVM exiting.

There is no RMI Registry specific java class path. It should use the same classpath as the rest of the Java system. You can set your classpath by specifying it on the command line, or in your OS environment. Though a little dated, this doc should point you in the right direction.

(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:

"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."

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.

An example of how to set classpath for rmiregistry

Win32:

set CLASSPATH=c:\home\ann\src;c:\home\ann\public_html\classes\compute.jar 

UNIX:

setenv CLASSPATH /home/ann/src:/home/ann/public_html/classes/compute.jar
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!