简体   繁体   English

覆盖rt.jar中的单个类

[英]Overriding single classes from rt.jar

I'm looking for a neat way to override a class from the bootstrap class path, rt.jar . 我正在寻找一种巧妙的方法来覆盖引导类路径rt.jar类。 The reason is OpenJDK7 bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7104625 原因是OpenJDK7错误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 . 修复此错误是一个微不足道的(请参阅链接的邮件列表帖子)更改为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). 所以我想知道是否有一种简单的方法可以在我的类路径上覆盖这个受影响的类,而不必重新打包/重建rt.jar(因此修复程序不会在下一次自动更新OpenJDK时丢失)。

Ideally, it would also affect Eclipse... 理想情况下,它也会影响Eclipse ......

I assume that java -Djava.system.class.loader=myClassLoader would work? 我假设java -Djava.system.class.loader=myClassLoader可以工作吗? 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) (注意:在我自己的代码中没有使用,但在Java AWT代码中很深)

您可以使用VM参数-Xbootclasspath/p将带有修补类的自己的JAR文件添加到引导类路径。

I believe the only supported way of doing this is to "patch" rt.jar by replacing the desired *.class file. 我相信唯一支持的方法是通过替换所需的* .class文件来“修补”rt.jar。 7-Zip can help you easily do this. 7-Zip可以帮助您轻松完成此操作。

This is exactly how Oracle supplied their double-parsing bug fix with their FPUpdater tool, which was essentially a script that did just this. 这正是Oracle用他们的FPUpdater工具提供他们的双解析错误修复的原因,这个工具本质上就是一个脚本。 ( Some history .) 有些历史 。)

我认为您可以尝试使用javaagent当JVM加载系统类并将其交换到您的系统类时,您必须拦截事件

I think @ziesemer is correct, but you may be able to use the classloader to replace the offending class when your app is bootstrapping. 我认为@ziesemer是正确的,但是当你的应用程序引导时,你可以使用类加载器来替换有问题的类。 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. 如果您不想担心在您下面进行JDK更新,这可能会更加清晰,尽管您必须将此引导类加载器代码粘贴到您正在处理的每个应用程序中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM