How to make the jvm load my java.lang.String instead of the one in rt.jar

后端 未结 2 1540
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 06:37

I studied java classloader rencently. Now I want to write a class that has the same package name and class name as one of class in rt.jar. For example, write a java.lang.Str

相关标签:
2条回答
  • 2020-12-18 06:58

    Have a look at the java.lang.instrumentation API: you can implement a ClassFileTransformer which ignores the passed-in byte array and returns a bute array containing your own implementation of java.lang.String instead.

    Better make sure that it's completely binary compatible with the original though or you will not get very far.

    0 讨论(0)
  • 2020-12-18 07:07

    You can do this using the -Xbootclasspath/p option at JVM startup:

    -Xbootclasspath/p:/path/to/yourimpl.jar
    

    /p stands for "prepend".

    Note: -Xbootclasspath isn't a standard java option, so JVMs by different vendors may not support it.

    0 讨论(0)
提交回复
热议问题