java - Intellij IDEA 无法导入 Gradle 项目 - "Could not initialize class javax.crypto.SunJCE_b"

标签 java intellij-idea gradle

我正在做一个 Gradle 项目。当我执行 gradle run 时,项目会下载依赖项并完美运行。这是我的 build.gradle 文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'application'

mainClassName = 'myProject.MyMainClass'

repositories {
    mavenCentral()
}

dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.7'
    compile 'org.jsoup:jsoup:1.7.2'

    testCompile "junit:junit:4.11"
}

jar {
    baseName = 'myproject-service'
    version = '0.1.0'
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

现在我想在Intellij IDEA中导入项目。

Import Gradle project >> Use default gradle wrapper (recommended) >> OK

但是,当我点击“确定”时,它会出现一个对话:

Could not initialize class javax.crypto.SunJCE_b

查看日志,它说

org.gradle.tooling.GradleConnectionException: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.3-bin.zip'.
...
Caused by: java.lang.NoClassDefFoundError: Could not initialize class javax.crypto.SunJCE_b
    at javax.crypto.KeyGenerator.a(DashoA13*..)
...
2015-03-18 21:31:17,751 [2354198]   WARN - nal.AbstractExternalSystemTask - Could not initialize class javax.crypto.SunJCE_b 
com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not initialize class javax.crypto.SunJCE_b
    at org.jetbrains.plugins.gradle.service.project.AbstractProjectImportErrorHandler.createUserFriendlyError(AbstractProjectImportErrorHandler.java:106)
...

我不知道如何让这个项目发挥作用。没有这个,我从外部存储库的导入都不能在 IDEA 中工作(它们都显示为红色)。任何帮助,将不胜感激。我在:

  • Intellij IDEA 13.1.6
  • Java EE 7 (jdk1.7.0_75.jdk)
  • Gradle 2.3
  • Mac 操作系统

最佳答案

解决方案:

仍然不知道问题是什么。我尝试了所有我能在网上找到的建议和我能想到的一切:安装不同版本的 java,安装不同的 IDEA,尝试使用原始密码策略文件,尝试使用无限强度策略文件等等。这些都不起作用。

然而,起作用的是选择“使用本地 gradle 分发”,而不是使用默认包装器。我给了它我的 gradle 安装路径 (/usr/local/gradle-2.3),通过运行 which gradle 找到(这将为您提供可执行文件的路径,即/usr/local/gradle-2.3/bin/gradle,但我只拿了目录部分)。现在我可以使用 gradle 进行构建了!!

我最好的猜测是 gradle 插件安装了一些其他的 gradle 发行版,这些发行版没有为我的项目正确设置。

我希望这对在 Intellij IDEA 中使用 gradle 遇到困难的其他人有所帮助。

关于java - Intellij IDEA 无法导入 Gradle 项目 - "Could not initialize class javax.crypto.SunJCE_b",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29137584/

相关文章:

java - 将节点从 JTree 拖放到 JLabel 上以执行操作

java - Java Servlet 的 URL 是什么

java - 如何在没有 IntelliJ 模板的情况下创建命令行应用程序?

java - Intellij 在编译期间看不到一些非公共(public) JDK 9 类

c# - ToString() 方法是否违反 SRP?

java - Java 中的正弦波声音发生器

java - Intellij IDEA 打开大括号格式后出现空行

android - 如何将 Pulsator4Droid 添加到 gradle 中?安卓

android-studio - 无法在Android Studio中单击 'Install Respository…'

gradle - Gradle和嵌套扩展