【问题标题】:Unable to find method sun.misc.Unsafe.defineClass找不到方法 sun.misc.Unsafe.defineClass
【发布时间】:2019-09-18 23:59:25
【问题描述】:

我正在使用jdk-10.0.2gradle 4.7,我在构建我的项目时遇到了这个错误。

    Unable to find method 'sun.misc.Unsafe.defineClass(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;'.

Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

【问题讨论】:

标签: java spring-boot gradle


【解决方案1】:

我有同样的问题(但使用JDK 11):

找不到方法 'sun.misc.Unsafe.defineClass(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;'。

与您一样使用版本gradle 4.7

我的gradle-wrapper.properties 文件是:

    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip

为了解决这个问题,我使用参数 distributionUrl 更改为 4.9 版本的包装器:

 distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip

并在没有任何错误的情况下重建项目。

【讨论】:

    【解决方案2】:

    Gradle 中 .gradle 文件的依赖有问题。 或 pom.xml 文件(如果您使用的是 Maven)。 造成这种情况的原因可能有很多: 版本,或冲突两次声明相同的依赖项。 要不然 检查您添加到库中的 jar_file 版本。

    【讨论】:

      【解决方案3】:

      你是否指定了here提到的模块依赖?从 JDK 9 开始,Unsafe API 似乎被隐藏了。

      因此,添加

      module jdk.unsupported {
          exports sun.misc;
          opens sun.misc;
          ...
      }
      

      对您的项目可能会有所帮助。

      【讨论】:

      • 我使用 java --list-modules 查看了模块列表,然后将此代码放入 jdk.unsupported@10.0.2 模块(已经存在)我还需要做什么?因为我仍然收到错误消息。
      • 您只提供错误消息,没有提供错误发生位置的信息。如果你不能提供Minimal, Complete, and Verifiable example我们只能猜测。
      猜你喜欢
      • 2011-10-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-07
      • 2020-03-16
      • 2021-05-31
      • 2018-10-28
      • 2011-04-01
      • 2017-02-15
      相关资源
      最近更新 更多