RMI Question - Where do clients get a definition for remote classes that have not been added to registry?

霸气de小男生 提交于 2019-12-02 01:06:27

First of all, realize that it's not necessary to set up dynamic classloading from the server in order to use RMI. If you compile the interface and implementation into both the client and server jars, then everything will work fine. That is how I've almost always implemented RMI.

If you have a good reason for loading the classes dynamically from the server, you'll need to set up an HTTP server somewhere that has the interfaces and implementation classes (preferably in a jar file, although a class directory will work too). This doesn't happen automatically as part of RMI, you need to build the jars and put them somewhere on your web server. Then launch the client with a system property indicating the URL to this jar file:

-Djava.rmi.server.codebase=http://webline/public/mystuff.jar

This is explained in full detail here: http://download.oracle.com/javase/1.5.0/docs/guide/rmi/codebase.html

If you use new to create new instances of the same type (say, T) as rObj, then of course the Java compiler knew the definition of T, and your application also knows it at runtime. In this case, no RMI is involved at all.

But maybe I misunderstood your question? How exactly do you "freely create instances of rObj"?

Update: I'm eating my words here, of course being able to compile the file, and having the class available on the classpath at runtime or two different issues. Since you were not mentioning the classpath at all, I was assuming you'd somehow ended up having the classes on the client-side anyway.

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