Re: need help about code mobility

Gregg Wonderly <[email protected]>
Newsgroups gmane.comp.java.sun.jini
Message-ID <[email protected]>
Mark Zaini wrote:
>     Class resolved=Class.forName(cls,true,classloader);

> -If I load the class A(which extends class B) with reflection Where
>  could I specify the URL of the remote class B ?
>
> -What classloader can I use to do this? a RMIClassLoader?

URLClassLoader ld = new URLClassLoader( new URL[] {
new URL("http://my.host.com/path/to/file.jar"),
new URL("http://my.host.com/path/to/dir/")
});

        // Make sure that this thread, in other class loading
        // needs has a reference to the "preferred" class loader
        // for loading remote classes.
        Thread.currentThread().setContextClassLoader( ld );

        // Load the class needed and all resolved classes will
        // have view of the 'ld' class loader to resolve any
        // classes not defined locally.
        Class resolved=Class.forName(cls,true,ld);

The use of PreferredClassLoader would be my suggested choice instead of
URLClassLoader so that you can arrange for your "non-platform" classes to always
be preferred so that you'll get the right version.

Gregg Wonderly

--------------------------------------------------------------------------
Getting Started:     http://www.jini.org/wiki/Category:Getting_Started
Community Web Site:  http://jini.org
jini-users Archive:  http://archives.java.sun.com/archives/jini-users.html
Unsubscribing:       email "signoff JINI-USERS"  to [email protected]
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.