我尝试使用Apache Flink版本1.16.2运行Flink作业,在使用./bin/flink run /Users/spartacus/icu-alarm/target/flink-kafka-stroke-risk-1.0-SNAPSHOT.jar
执行作业时遇到以下错误:
java.lang.NoClassDefFoundError: org/apache/flink/connector/kafka/source/KafkaSource
at hes.cs63.CEPMonitor.StrokeRiskAlarm.main(StrokeRiskAlarm.java:30)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:355)
at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:222)
at org.apache.flink.client.ClientUtils.executeProgram(ClientUtils.java:98)
at org.apache.flink.client.cli.CliFrontend.executeProgram(CliFrontend.java:843)
at org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:240)
at org.apache.flink.client.cli.CliFrontend.parseAndRun(CliFrontend.java:1087)
at org.apache.flink.client.cli.CliFrontend.lambda$main$10(CliFrontend.java:1165)
at org.apache.flink.runtime.security.contexts.NoOpSecurityContext.runSecured(NoOpSecurityContext.java:28)
at org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1165)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.connector.kafka.source.KafkaSource
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at org.apache.flink.util.FlinkUserCodeClassLoader.loadClassWithoutExceptionHandling(FlinkUserCodeClassLoader.java:67)
at org.apache.flink.util.ChildFirstClassLoader.loadClassWithoutExceptionHandling(ChildFirstClassLoader.java:65)
at org.apache.flink.util.FlinkUserCodeClassLoader.loadClass(FlinkUserCodeClassLoader.java:51)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 14 more
我相信这个错误与缺少依赖项或类路径问题有关。下面是我的代码中将Kafka设置为源代码的相关部分:
// KafkaSource setup
KafkaSource<String> source = KafkaSource.<String>builder()
.setBootstrapServers("localhost:9092")
.setGroupId("stroke-risk-group")
.setTopics(Arrays.asList("patient-data-topic"))
.setDeserializer(KafkaRecordDeserializationSchema.valueOnly(StringDeserializer.class))
.setValueOnlyDeserializer(new SimpleStringSchema())
.build();
DataStreamSource<String> patientData = env.fromSource(source, WatermarkStrategy.noWatermarks(), "Kafka Source");
我已经在我的项目中包含了必要的Flink依赖项,我正在使用Maven来构建它。然而,我仍然遇到这个问题。是什么原因导致了这个错误,我该如何解决它?
代码-> https://github.com/IshaanAdarsh/icu-alarm
附加信息:
- Flink版本:1.16.2
- Java版本:11
- 使用的IDE:IntelliJ IDEA
1条答案
按热度按时间nuypyhwy1#
我分析了您的pom.xml文件,注意到多个依赖项的范围被设置为
provided
。这意味着您需要手动加载它们。通过删除作用域或将其更改为
compile
,它将检索依赖项并自动加载它们。请确保在尝试运行
StrokeRiskAlarm
之前运行mvn clean install
。