Overriding individual classes from rt.jar

I am looking for a neat way to override a class from the bootstrap class path, rt.jar . The reason for the OpenJDK7 error is http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7104625

The fix for this error is trivial (see related email), change to sun.awt.X11.XComponentPeer . Therefore, I was wondering if there is an easy way to override only one affected class in my class path without repackaging / rebuilding rt.jar (so the fix will not be lost the next time OpenJDK is automatically updated).

Ideally, this will also affect Eclipse ...

I assume java -Djava.system.class.loader=myClassLoader will work? Is there any other way to override one class with such a “fix”? (Note: not used in my own code, but deep in Java AWT code)

+4
source share
4 answers

You can use the VM -Xbootclasspath/p to add your own fixed-class JAR file to the boot class path.

+9
source

I believe that the only supported way to do this is to “pay” rt.jar by replacing the desired * .class file. 7-Zip will help you do this easily.

This is how Oracle provided two-parsing bug fixes using its FPUpdater tool, which essentially was a script that did just that. ( Some story .)

+1
source

I think you can try using javaagent. You should catch the event when the JVM loads the system class and replaces it with yours.

+1
source

I think @ziesemer is correct, but you can use the class loader to replace the intruder class when your application loads. This might be cleaner if you don't want to worry about updating the JDK under you, although you will have to embed this bootloader boot code in every application you work on.

0
source

Source: https://habr.com/ru/post/1385352/


All Articles