覆盖 rt.jar 中的单个类
我正在寻找一种巧妙的方法来覆盖引导类路径 rt.jar
中的类。 原因是OpenJDK7 bug https://bugs.java.com/bugdatabase/view_bug?bug_id =7104625
此错误的修复是一个简单的更改(请参阅链接的邮件列表帖子) sun.awt.X11.XComponentPeer
。所以我想知道是否有一种简单的方法可以覆盖我的类路径上的这个受影响的类,而不必重新打包/重建 rt.jar (这样修复就不会在 OpenJDK 的下一次自动更新中丢失)。
理想情况下,它也会影响 Eclipse...
我认为 java -Djava.system.class.loader=myClassLoader 会起作用吗?有没有其他方法可以用这样的“修补程序”覆盖单个类? (注:在我自己的代码中没有使用,但在Java AWT代码中很深入)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 VM 参数
-Xbootclasspath/p
将您自己的 JAR 文件(带有修补的类)添加到启动类路径中。You can use the VM parameter
-Xbootclasspath/p
to prepend your own JAR file with the patched class to the boot class path.我相信唯一受支持的方法是通过替换所需的 *.class 文件来“修补”rt.jar。 7-Zip 可以帮助您轻松做到这一点。
这正是 Oracle 通过其 FPUpdater 工具提供双重解析错误修复的方式,该工具本质上是一个执行此操作的脚本。 (一些历史记录。)
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.)
我想你可以尝试使用 java代理
当 JVM 加载系统类并将其交换到您的系统类时,您必须拦截事件
I think you can try to use javaagent
You must intercept event, when JVM loads system class and swap it to yours
我认为@ziesemer 是正确的,但是当您的应用程序引导时,您也许可以使用类加载器来替换有问题的类。如果您不想担心底层的 JDK 更新,这可能会更干净,但您必须将此引导类加载器代码粘贴到您正在开发的每个应用程序中。
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.