Hiyall,
i was mucking about with an on the fly compiler (
java that modifies itself ) and have found that if the class has not been used ( called ) then you can modify it / replace it then call it. Otherwise if the class has been 'used' the class is loaded into memory and you can change the class all you want on the disk but it wont happen unless you restart the app and call that class ... doh. ( this would seem to be a security issue ).
However have you tried a class loader .. I use this to load the compiled classes that my app modifies then execute them. eg ...
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
public class cLoader extends URLClassLoader
{
protected cLoader(URL[] urls, ClassLoader parent) {
super(urls, parent);
}
public Class loadClass(
String name) throws ClassNotFoundException {
System.out.println("loadClass: " + name);
return super.loadClass(name);
}
protected Class findClass(String name) throws ClassNotFoundException {
Class clas = super.findClass(name);
System.out.println("findclass: loaded " + name +
" from this loader");
return clas;
}
}