Javaassist class file Reload issue

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.