This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Changing classpath at runtime
- From: Per Bothner <per at bothner dot com>
- To: kawa at sourceware dot org
- Date: Sun, 29 May 2011 09:05:34 -0700
- Subject: Re: Changing classpath at runtime
- References: <m2pqn2wtmy.fsf@gmail.com>
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/