How to implement a method in Java replacement or hot replacement rt.jar?

public class Main{
    public staic void main(String[] args){
        System.out.println(Class.forName("a.b.old.C"));
    }
}

Class.forName needs to be changed due to some special requirements, and when using this method, if the package name of the passed class contains a certain path, it will be replaced with another path. For example, the class obtained by Class.forName ("a.b.old.XXX") will be "a.b.new.XXX".

ask me how to achieve the appeal effect, and can not modify the rt.jar

Apr.05,2021

do not use class.forname, use a custom classloader


can be outsourced at Class.forName.

  

first of all, you can't put rt.jar in java_home. If rt.jar can't move, change the environment variable java_home, so that bootstrap classloader can't find rt.jar. Then register a custom classloader to load all the jar packages in java_home. By the way, tamper with rt.jar

.
Menu