java.lang.ClassNotFoundException: org.apache.flink.streaming.connectors.kafka.KafkaSerializationSchema
Flink從Kafka中讀取數據,本地運行時一切正常,但打包jar提交服務器時一直無法運行,日志報錯 java.lang.ClassNotFoundException: org.apache.flink.streaming.connectors.kafka.KafkaSerializationSchema,
猜測是對應的connector jar包沒有引入,重啟Flink無效,重新打包無效,懷疑少加了build但是搜了maven倉庫仍然不會改。
百度發現Flink社區及StackOverflow都有人提出類似的問題,但是都看不太懂,最后還是從這一篇找到解決方案,博主說的沒有特別清楚:https://www.jianshu.com/p/f99b6635fbc5
在pom.xml加入如下代碼,其中“
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>com.google.code.findbugs:jsr305</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>log4j:*</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<!-- Do not copy the signatures in the META-INF folder.
Otherwise, this might cause SecurityExceptions when using the JAR. -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>site.buzhou.source.TestKafka</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>