Re: Dynamic Class downloading

Peter Jones - JavaSoft East <[email protected]>
Newsgroups gmane.comp.java.sun.rmi
Message-ID <20051018002636.GF7958@east>
> Does your point about class loaders mean that, say, I am using a
> URLClassLoader which is pointing to the RMI Server Code base and
> then I make this class loader to be the one that also loads my code
> snippet, then do you think it would work without having the
> interface classes on the client classpath?

Depending on exactly what you mean, it may work-- essentially you
would be bootstrapping the RMI client code from a remote class server.

> I tried this option too, but of no luck. I still get the
> NoClassDefFoundError.
>
> For example (the pseudo code might look like this):
>
> public ClassA
> {
> ClassA()
> {
> Object o = context.lookup("example");
> ExampleHome home = (ExampleHome) o;
> }
> }
>
> main()
> {
> URLClassLoader ucl = new URLClassLoader(new URL[] {new URL("
> http://rmi.server.codebase:port/")});
> ucl.loadClass("ClassA");
> }

Sorry, but I'm not understanding your pseudo-code example well enough.
What class is the main method in?  Isn't some of its code missing?  I
would expect the result of the loadClass invocation (which would be
better as a Class.forName invocation, BTW) to be used to reflectively
instantiate ClassA and then invoke it.  Did you make sure that ClassA
was itself not in the client VM's class path (which would have
thwarted usage of the downloaded version)?

We would be better able to comment on a more complete example (along
with the complete exception trace, command lines, etc.).  It might
also help if you explained what problem you are trying to solve.

Also, note that if the downloaded client code is defined by your own
class loader (not the system class loader), then in order to avoid a
ClassCastException or ClassNotFoundException when unmarshalling the
results of remote invocations made by the client code, you may need to
set the thread context class loader to your loader (the one used to
download the client code) around invocations of the client code-- like
a browser does around invocations of applet code, for example.

-- Peter

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.