Search code examples
javaclassloaderjava-7

Overriding single classes from rt.jar


I'm looking for a neat way to override a class from the bootstrap class path, rt.jar. The reason is OpenJDK7 bug https://bugs.java.com/bugdatabase/view_bug?bug_id=7104625

The fix for this bug is a trivial (see linked mailing list post) change to sun.awt.X11.XComponentPeer. So I was wondering if there is an easy way to override just this one affected class on my classpath, without having to repack/rebuild rt.jar (so the fix isn't lost on the next automatic update of OpenJDK).

Ideally, it would also affect Eclipse...

I assume that java -Djava.system.class.loader=myClassLoader would work? Is there any other way to override a single class with such a "hotfix"? (Note: not used in my own code, but deep in Java AWT code)


Solution

  • You can use the VM parameter -Xbootclasspath/p to prepend your own JAR file with the patched class to the boot class path.