Javaassist
Classpool is an object pool of javassist,
Pool.insertclasspath (String), this method can add objects to the pool, but there is a problem, if we add the pool in this way, class changes, the pool file is still the original class file.
Did not reload the class file, and the Classpool class did not provide a corresponding method.
In addition to a ctclass removecached (String classname), this method. Unfortunately, it's not public.
So the way is as follows:
public class Reclasspool extends classpool{@Override public ctclass removecached (String classname) { return ( Ctclass) Classes.remove (classname); }}
Redefine an object pool, overriding the parent class, set to public.
Ctclass Claname = null;try {//if (!classpath.endswith (". Jar")) pool.removecached (PackagePath); Claname = Pool.get (PackagePath);
When retrieving a class object, the cache is cleared and the class file object is retrieved again. So it's loaded dynamically.
Get!
Javaassist class file Reload issue