简体   繁体   English

Java 6和SwingUtilities2

[英]Java 6 and SwingUtilities2

There is component within the application that uses com.sun.java.swing.SwingUtilities2 Now I understand that this class shouldn't be used, but it's a component within the system that uses it. 应用程序中有组件使用com.sun.java.swing.SwingUtilities2现在我明白不应该使用此类,但它是系统中使用它的组件。

Therefore since it's no longer available in Java 6 I get a NoClassDefFoundError. 因此,由于它在Java 6中不再可用,我得到NoClassDefFoundError。 How can I get around this issue without having to upgrade the component as I don't yet know if that's an option. 如何在不必升级组件的情况下解决此问题,因为我还不知道这是否是一个选项。

If you have absolutely no other choice, then you should figure out exactly what it was that the class is using from SwingUtilities2, and then make proxies for that functionality in your own SwingUtilities2. 如果您绝对没有其他选择,那么您应该从SwingUtilities2中确切地弄清楚该类正在使用什么,然后在您自己的SwingUtilities2中为该功能创建代理。 You can then stick it in your own com.sun.java.swing package, which will overlap with the original one, and if the same class loader that loads your component is also aware of SwingUtilities2, then the one will see the other and your application will work. 然后你可以将它粘贴在你自己的com.sun.java.swing包中,它将与原始包重叠,如果加载你的组件的同一个类加载器也知道SwingUtilities2,那么那个将看到另一个和你的应用程序将工作。

Depending on what the component is, and what it used out of SwingUtilities2, this could be significantly harder than upgrading it or even rewriting it. 根据组件的内容以及SwingUtilities2使用的内容,这可能比升级甚至重写它要困难得多。

Da-dum! DA-达姆! This is precisely why you should pay attention to those pesky warnings admonishing you not to rely upon internals of the JVM! 这正是为什么你应该注意那些讨厌的警告,告诫你不要依赖JVM的内部!

Just a though, I don't know if this would work. 但是,我不知道这是否有效。

Try pulling out the SwingUtilities2 class and put it in a patch jar, include this jar in your classpath. 尝试拔出SwingUtilities2类并将其放入补丁jar中,在类路径中包含此jar。 Hopefully this works until you can change the source. 希望这有效,直到您可以更改源。

The only correct way (out of hacking) is to ask vendor to fix and rebuild this component to Java 6. The possible working way is copy sun.swing.SU2 to com.sun...SU2 and package it into separate jar (eg java6fix.jar) and try to run your application. 唯一正确的方法(出于黑客攻击)是要求供应商修复并重建此组件到Java 6.可能的工作方式是将sun.swing.SU2复制到com.sun ... SU2并将其打包到单独的jar中(例如java6fix.jar)并尝试运行您的应用程序。 It will be fine if you add this patch jar into jvm bootclasspath. 如果你将这个补丁jar添加到jvm bootclasspath中就可以了。 The best patch should be to create own com.sun..SU2 and delegate all calls to sun.swing.SU2. 最好的补丁应该是创建自己的com.sun..SU2并委托对sun.swing.SU2的所有调用。 And take a look for different version of component which support Java6 maybe also from different vendor. 并且可以查看支持Java6的不同版本的组件,也可能来自不同的供应商。 Also if the problem is only in the mentioned line ((Boolean)c.getClientProperty(AA_TEXT_PROPERTY_KEY)); 此外,如果问题仅在提到的行中((Boolean)c.getClientProperty(AA_TEXT_PROPERTY_KEY)); then you may put your own client property for this component to prevent NPE. 那么你可以为这个组件放置自己的客户端属性以防止NPE。 When you take this path you can just simply create your own com.sun...SU2.AA_TEXT_PROPERTY_KEY and call c.setClientProperty(AA_TEXT_PROPERTY_KEY, true) on this component. 当您使用此路径时,您只需创建自己的com.sun ... SU2.AA_TEXT_PROPERTY_KEY并在此组件上调用c.setClientProperty(AA_TEXT_PROPERTY_KEY,true)。 Also try to disable anti aliasing check on component if possible. 如果可能,还尝试禁用组件上的抗锯齿检查。

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

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