【问题标题】:Making the Storm JARs compile-time only in a Gradle project仅在 Gradle 项目中使 Storm JAR 成为编译时
【发布时间】:2013-07-02 09:15:45
【问题描述】:

我正在尝试构建一个包含 Storm 项目的 Gradle 项目。为了在 Storm 上运行这个项目,我必须首先创建一个 JAR 文件并让 Storm 运行我的拓扑,例如

storm jar myJarFile.jar com.mypackage.MyStormMainClass

我遇到了问题,因为 Gradle 默认在编译时和运行时都包含 Storm 依赖项。这会导致以下异常:

Exception in thread "main" java.lang.RuntimeException: Found multiple defaults.yaml resources. You're probably bundling the Storm jars with your topology jar.

给出的异常实际上很有帮助,并提示我们找出问题的根本原因。解决方案是在使用 Gradle 编译时包含 Storm 依赖项,但在生成最终 JAR 文件时不包含。

有谁知道如何解决这个问题? StackOverflow 上的其他帖子并没有解决问题。如果您粘贴代码,请确保它实际运行。

谢谢!

【问题讨论】:

  • 让我们知道您的问题是否已得到解答。

标签: maven gradle apache-storm


【解决方案1】:

下面我将an answer of mine 引用为similar thread on the storm-user mailing list

就我而言,我选择使用 fatJar plugin 来实现 Gradle。

buildscript {
    repositories {
        mavenCentral()
        mavenRepo url: "http://clojars.org/repo"
    }
    dependencies {
        // see https://github.com/musketyr/gradle-fatjar-plugin
        classpath 'eu.appsatori:gradle-fatjar-plugin:0.2-rc1'
    }
}

// When using this plugin you can build a fat jar / uberjar with 'gradle fatJar'
apply plugin: 'fatjar'

dependencies {
    compile 'storm:storm:0.8.2', {
        ext {
            fatJarExclude = true
        }
    }
}

您通过以下方式构建胖罐:

$ gradle clean fatJar

最好, 迈克尔

PS:值得一提的是,我还在 Running a Multi-Node Storm Cluster 上写了关于如何解决上述问题的博客。该帖子包含可能对您有帮助也可能没有帮助的其他信息和陷阱。

【讨论】:

  • +1 为您博客上的精彩文章。知道可以排除哪些其他 JAR 吗?我很想把我的胖罐子剪下来,因为它现在看起来有点太胖了……
  • 到目前为止,我只排除了 Storm 依赖项本身,因此根据我自己的实践经验,我无法建议您也排除其他部门是否安全。
猜你喜欢
  • 2015-12-09
  • 2010-09-23
  • 2016-03-03
  • 2015-03-12
  • 2018-03-03
  • 2014-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多