java.lang.NoClassDefFoundError: sun/net/www/protocol/https/DefaultHostnameVerifier

java.lang.NoClassDefFoundError: sun/net/www/protocol/https/DefaultHostnameVerifier

我正在将我没有源代码的 Java Swing 应用程序从 Java 8 移动到 Java 10。

我先运行进入:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/ws/WebServiceException

我成功解决了。正如 和其他网站所解释的那样,自 Java 9 起,模块已从 JDK 中移出。这意味着我必须将应用程序的依赖关系带回我的类路径中 运行.

现在我得到:

java.lang.NoClassDefFoundError: sun/net/www/protocol/https/DefaultHostnameVerifier

但我似乎找不到那个依赖项在哪里。我发现 post 建议更改代码,但这不是我的选择。我还能尝试什么?

sun 包 类 始终意味着内部 JDK 实现细节,并不意味着在应用程序代码中使用。现在 JDK 被 Project Jigsaw this class is no longer available and that's a good thing. This is not anything new, see Why Developers Should Not Write Programs That Call 'sun' Packages 模块化:

The sun.* packages are not part of the supported, public interface. A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.

解决方案是更改您的应用程序代码以与 JDK 10 兼容。如果您的应用程序代码无法更改,则应保留 JDK 8.