Re: Using an interface between two dl'ed applications

Gregg Wonderly <[email protected]> Mon, 19 Jan 2009 10:19:46 -0600
Newsgroups gmane.comp.java.sun.jini
Message-ID <[email protected]>
Calum Shaw-Mackay wrote:
> Given a system 'A' that allows objects 'B' and 'C' to be deployed to it, 
> where 'C' has an interface dependency on 'B'. Also 'B' and 'C" are 
> independently deployed, with potentially different codebases, but with 
> the same interface definition (compiled) in each.
> 
> When 'C' requests access to 'B' via a dynamic proxy generated from the 
> Interface declared in 'B's codebase, I get a ClassNotFoundException, I'm 
> assuming that this is because B's classes are being declared in a 
> different classloader to 'C's.
> 
> Is there any way to get around this - any particular usage of 
> PREFERRED.LIST?

The standard java URLClassLoader (or when you have no PREFERRED.LIST) provides 
the most often correct handing for interfaces by looking up the classloader 
chain for resolution before loading locally.

PREFERRED.LIST allows you to say "use my downloaded version always", and in 
general solves the "class compatibility" issue by allowing a new version of a 
class to be downloaded and used in preference to the version that might already 
exist in the classloader tree.

Without more information, I'd suggest that perhaps this is more likely a context 
class loader issue.  The thread of execution that C was loaded in, is not the 
same thread of execution that B is loaded in and B's context class loader is 
used to resolve the interface and it sees the A parent instead of the C context 
class loader (the PreferredClassLoader that loaded C).

Something like this

A->C->load interface with C classloader
A->B->load interface with B classloader

So, if the interface is not visible in the "A" class loader, than you must force 
the path to be A->C->B so that the interface is loaded from C.

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]