为什么要在pom.xml中指定主类?
从图中可以看到两个jar。kafkastormtest1-0.0.1-SNAPSHOT.jar时运行包,是你使用mvn打包之后你的工程下的代码以及jar包,kafkastormtest1-0.0.1-SNAPSHOT-jar-with-dependencies.jar,这个是依赖包,包含你的源码和相应的包,以及依赖的包。
如果在使用kafkastormtest1-0.0.1-SNAPSHOT.jar向集群提交topology的时候出现以下错误:
这种报错的解决办法:
在你的项目的根目录下找到pom.xml。在这个配置文件中加上如下内容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>kafkastorm.kafkastorm.TopicMsgTopology</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
注意:一定要将上面的内容放入<pligins>上述内容</plugins>。
这样就可以保证直接提交kafkastormtest1-0.0.1-SNAPSHOT.jar能够成功提交到集群中。