【问题标题】:Fat JAR with Kotlin and Apache Spark 2.3带有 Kotlin 和 Apache Spark 2.3 的胖 JAR
【发布时间】:2018-04-27 01:32:36
【问题描述】:

我正在使用 gradle 构建混合 Kotlin 和 Apache Spark 的项目,但是一旦我声明了 spark 依赖项,我生成的 Fat JAR 就无法正常工作。否则它将起作用。源代码甚至没有从 Spark 导入任何东西

buildscript {
    ext.kotlin_version = '1.2.40'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'kotlin'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    // uncomment this line to get main class 'myownpkg.SparkApplicationKt' 
    // not found error
    // compile 'org.apache.spark:spark-core_2.11:2.3.0'
}

jar {
    manifest { attributes 'Main-Class': 'myownpkg.SparkApplicationKt' }
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

【问题讨论】:

  • uncomment this line?哪条线?
  • 我得到了这个有效的添加指令到 jar 部分,它将排除 'META-INF/*'

标签: apache-spark gradle jar kotlin


【解决方案1】:

经过一些实验,我意识到生成的 JAR 中有很多重复的文件,导致运行时找不到所需的 .class。 它是在启用 Spark 后触发的,因为它是导致 META-INF 文件夹下具有相同文件路径的其他依赖项滚雪球的依赖项

exclude 'META-INF/*'

那一行是避免重复的诀窍,但最终 JAR 中仍然会有一个 META-INF 文件夹

【讨论】:

    【解决方案2】:

    主要原因是因为您没有创建具有必要依赖项的“FatJar”工件。配置中的编译目录只包含编译后的源代码。

    maven central 开始,您至少需要 spark-core 所需的 50 个编译依赖项。您是否考虑过使用shadow plugin

    看看this thread gradle讨论。

    【讨论】:

    • 这不是真的,实际上它会遍历所有的 dep 并且它们在最终的 JAR 中。看看报错信息是关于不能加载主类,不是deps
    猜你喜欢
    • 2019-08-12
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 2017-07-18
    • 2023-04-04
    • 2018-10-23
    • 1970-01-01
    • 2017-08-18
    相关资源
    最近更新 更多