Overriding single classes from rt.jar

喜欢而已 提交于 2019-11-30 18:01:05

问题


I'm looking for a neat way to override a class from the bootstrap class path, rt.jar. The reason is OpenJDK7 bug http://bugs.sun.com/bugdatabase/view_bug.do?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)


回答1:


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




回答2:


I believe the only supported way of doing this is to "patch" rt.jar by replacing the desired *.class file. 7-Zip can help you easily do this.

This is exactly how Oracle supplied their double-parsing bug fix with their FPUpdater tool, which was essentially a script that did just this. (Some history.)




回答3:


I think you can try to use javaagent You must intercept event, when JVM loads system class and swap it to yours




回答4:


I think @ziesemer is correct, but you may be able to use the classloader to replace the offending class when your app is bootstrapping. This may be cleaner if you don't want to worry about the JDK updating underneath you, though you'd have to stick this bootstrapping classloader code into every app you are working on.



来源:https://stackoverflow.com/questions/8433047/overriding-single-classes-from-rt-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!