找到了多个defaults.yaml资源

7 java maven apache-storm

当我试图提交拓扑时,我发现了这一点

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)
Run Code Online (Sandbox Code Playgroud)

但是在pom.xml中更新后出现此错误

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

因为我是一个错误

An exception occured while executing the Java class. storm/trident/state/StateFactory
Run Code Online (Sandbox Code Playgroud)

这里是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>
Run Code Online (Sandbox Code Playgroud)

pom文件的第2部分

<executions>
    <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
            <goal>single</goal>
        </goals>
    </execution>
</executions>
Run Code Online (Sandbox Code Playgroud)

pom文件的第3部分

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
    </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)

Mat*_*Sax 13

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

范围storm-core设置为<scope>provided</scope>默认值,因为无论如何这些类文件在集群中都可用.provided告诉maven,这些类不能包含在jar已组装的文件中,从而减小了jar的大小.此外,如果多次提供文件,这可以避免冲突 - default.yaml如果您将范围更改为,则会发生这种情况compile.对于这些情况,所有文件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>
Run Code Online (Sandbox Code Playgroud)