I know of two ways...
Using a custom classloader:
Tomact for instance will reload classes in a webapp context if the context
has been marked as reloadable. It should be possible to
write a custom classloader that does the same, some thought about this:
http://mindprod.com/jgloss/reloading.html
Using JPDA:
Eclipse for instance can reload classes during debugging using JVM
instrumentation.
Cheers,
Martin.
> Is there (or could there be) a way to make the VM unload or reload a
> class?
Thomas Hawtin - 29 Jul 2006 09:45 GMT
> Using a custom classloader:
Or a bog standard, uncustomised URLClassLoader.
http://download.java.net/jdk6/docs/api/java/net/URLClassLoader.html#newInstance(
java.net.URL[])
> Tomact for instance will reload classes in a webapp context if the context
> has been marked as reloadable. It should be possible to
> write a custom classloader that does the same, some thought about this:
It's very easy to write code that will leak. For instance java.beans,
common uses of ThreadLocal and loading JDBC driver can all cause the
class loader and all of its classes and their static data to leak.
Tom Hawtin
> Is there (or could there be) a way to make the VM unload or reload a
> class?
Yes. It requires that there be no references to the class. However, the
class loader maintains a reference to each class that it loads. Thus, you
must deal with the class loader, by creating (if I recall correctly) a custom
class loader. This is not as hard as it may sound.
A solution is shown in:
Java Reflection in Action (In Action series) by Ira R. Forman and Nate
Forman (ISBN: 1932394184 )
The book also explains the limits of this approach.
Disclaimer: I have no connection with the publisher or the authors. Just a
satisfied reader.

Signature
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *