This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Changing classpath at runtime


On 05/28/2011 11:46 AM, Helmut Eller wrote:
Is it possible to change the classpath at runtime?

I'd like to do something like

(add-to-classpath ".../foo.jar")

<... use classes in foo.jar ...>

Is Kawa's prepared for that or is the classpath de facto immutable?

First you need to create a "delegating" ClassLoader. This manages a
dynamic search path of sub-ClassLoaders or just jar files directly. A request to
the delegating ClassLoader is forwarded to the sub-ClassLoaders or the
jar files.


Then you need to make sure class loading uses this delegating ClassLoader.
I assume you can use java.lang.Thread#setContextClassLoader. I'm not familiar
with how to do this in practice. It's possible you might need to start a fresh
thread.


There is probably example code and articles available on the internet,
but I don't haven't anything to point you at.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]