2013-07-02 62 views
6

我正在尝试构建一个包含Storm项目的Gradle项目。为了在Storm上运行这个项目,我必须先创建一个JAR文件,让Storm运行我的拓扑,例如仅在Gradle项目中编译时风暴JAR编译时间

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上的其他帖子没有解决问题。如果您粘贴代码,请确保它实际运行。

谢谢!

+0

让我们知道您的问题是否已被回答。 –

回答

1

下面我引用an answer of minesimilar thread on the storm-user mailing list

在我的情况下,我选择使用fatJar plugin为此目的的Gradle。

$ gradle clean fatJar 

最佳, 迈克尔

PS:

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 
     } 
    } 
} 

你可以通过建立脂肪罐子对于什么是值得我也博客上讲述如何如上在Running a Multi-Node Storm Cluster描述的解决这个问题。该文章包含了可能会或可能不会对您有所帮助的其他信息和陷阱。

+0

+1,用于博客上的精彩文章。知道还有哪些JAR可以排除?我很想修剪我的肥缸,因为它现在看起来有点太胖... –

+0

到目前为止,我只排除了风暴依赖本身,因此根据我自己的实践经验,我不能告诉你它是否排除其他代表也是安全的。 –