【问题标题】:Found multiple defaults.yaml resources发现多个 defaults.yaml 资源
【发布时间】:2015-10-26 21:51:25
【问题描述】:

当我尝试提交拓扑时,我发现了这个

Exception in thread "main" java.lang.RuntimeException: Found multiple defaults.yaml resources. You're probably bundling the Storm jars with your topology jar.
at backtype.storm.utils.Utils.findAndReadConfigFile(Utils.java:115)
at backtype.storm.utils.Utils.readDefaultConfig(Utils.java:135)
at backtype.storm.utils.Utils.readStormConfig(Utils.java:155)
at backtype.storm.StormSubmitter.submitTopology(StormSubmitter.java:61)
at backtype.storm.StormSubmitter.submitTopology(StormSubmitter.java:40)
at trident.myproject.main(myproject.java:288)

但是这个错误是在pom.xml中更新后出现的

<scope>compile</scope> instead of <scope>provided</scope>

因为我是一个错误

An exception occured while executing the Java class. storm/trident/state/StateFactory

这里是pom文件

<plugins>
    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <archive>
                <manifest>
                    <mainClass>trident.myproject</mainClass>
                    <!-- <mainClass>crawler.Crawler</mainClass> -->
                </manifest>
            </archive>
        </configuration>

pom 文件的第二部分

<executions>
    <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
            <goal>single</goal>
        </goals>
    </execution>
</executions>

pom 文件第三部分

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
    </plugin>
</plugins>

【问题讨论】:

  • 您的 jar 中似乎仍然包含defaults.yaml。打包前有没有试过mvn clean?你如何包装你的罐子?也许您需要明确排除该文件。
  • 是的,我尝试 mvn clean 现在项目的 pom 文件包含 provided 并尝试使用此命令 mvn compile exec:java -Dexec.classPathScope=compile -Dexec.mainClass =trident.TheProject,结果是执行 Java 类时发生异常。风暴/三叉戟/国家/国家工厂
  • 你能发布错误消息/堆栈跟踪吗?您是否尝试通过storm jar myJarFile.jar package.and.MyMainClass 提交?
  • 是的,我使用了storm jar target/jarfile.jar trident.class 拓扑名称,但我有一个问题,我尝试使用 mvn compile exec:java -Dexec.classPathScope= 在本地模式下运行项目compile -Dexec.mainClass=trident.class 然后出现错误“执行 Java 类时发生异常。storm/trident/state/StateFactory”有人建议我将 pom 文件的范围从提供更改为编译,然后它运行良好然后得到尝试提交拓扑时出现上述错误!但是项目和编码器的范围没有改变,所以在找到 statefactory 时出错
  • 本文中的上一个错误stackoverflow.com/questions/33343686/…

标签: java maven apache-storm


【解决方案1】:

LocalCluster 或通过StormSubmitter(这是项目中的默认设置)远程运行拓扑有根本的区别。

storm-core 的范围默认设置为&lt;scope&gt;provided&lt;/scope&gt;,因为这些类文件无论如何都在集群中可用。 provided 告诉 maven,这些类不能包含在组装的 jar 文件中,从而减小 jar 的大小。此外,如果多次提供文件,这可以避免冲突——如果您将范围更改为compiledefault.yaml 就会发生这种情况。对于这种情况,来自storm-core 的所有文件都打包到您jar 中并提交给集群。 Storm 找到文件defaults.yaml“本地”(即本地在集群中的工作机器上)和您的jar。因此,Storm 不知道使用哪一个并引发错误。

但是,如果您在本地运行,provided 也会排除这些类文件。当然,这些文件在本地不是自动可用的,但在启动本地 JVM 时必须包含在 CLASSPATH 中。由于provided 排除了storm-core 中的文件,您会得到ClassNotFound 异常。

作为每次要提交到不同环境时更改范围的替代方法,您可以将范围设置为compile,并在maven-jar-plugin 设置中明确包括拓扑 Main/Bolt/Spout 类。这种显式包含会自动排除 jar 中的所有其他文件,即来自 storm-core 的所有文件。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <version>2.6</version>

  <executions>
    <execution>
      <id>MyTopology</id>
      <phase>package</phase>
      <goals>
        <goal>jar</goal>
      </goals>
      <configuration>
        <includes>
          <include>my/topology/package/**/*.class</include>
        </includes>
      </configuration>
    </execution>
  </executions>
</plugin>

【讨论】:

  • 感谢您的精彩解释,我现在就试试
  • pom 文件的第 2 部分我应该更改它吗?我发布了部分 pom 文件
  • 使用maven-jar-plugin 代替maven-assembly-plugin 或通过&lt;dependencySet&gt; 排除storm-core: maven.apache.org/plugins/maven-assembly-plugin/examples/single/…
  • 我更改为 maven-jar-plugin 但使用 mvn clean 时生成错误“在执行中指定了‘single’,但在我发布的 pom 的第 2 部分中未在插件中找到
  • 看看我的回答。目标必须是jar;不是single
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-31
  • 2023-03-13
  • 1970-01-01
  • 2017-06-08
  • 2021-05-31
  • 2019-05-02
相关资源
最近更新 更多