java.lang.NoClassDefFoundError 提交 Flink 作业时



我正在尝试提交一个使用 Scala 2.11 创建的 Flink 作业,该作业在本地 Flink 集群中使用 Twitter 流 API,方法是在命令行中运行:

flink run -c org.myClass C:pathtojarFile.jar

并得到以下错误:

2019-06-09 23:40:47,758 WARN  org.apache.flink.runtime.webmonitor.handlers.JarRunHandler    - Configuring the job submission via query parameters is deprecated. Please migrate to submitting a JSON request instead.
2019-06-09 23:40:47,762 ERROR org.apache.flink.runtime.webmonitor.handlers.JarRunHandler    - Unhandled exception.
org.apache.flink.client.program.ProgramInvocationException: The program caused an error: 
    at org.apache.flink.client.program.OptimizerPlanEnvironment.getOptimizedPlan(OptimizerPlanEnvironment.java:93)
    at org.apache.flink.client.program.PackagedProgramUtils.createJobGraph(PackagedProgramUtils.java:80)
    at org.apache.flink.runtime.webmonitor.handlers.utils.JarHandlerUtils$JarHandlerContext.toJobGraph(JarHandlerUtils.java:126)
    at org.apache.flink.runtime.webmonitor.handlers.JarRunHandler.lambda$getJobGraphAsync$6(JarRunHandler.java:142)
    at java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/apache/flink/streaming/connectors/twitter/TwitterSource$EndpointInitializer
    at msciss.TwitterHashtagCounter.main(TwitterHashtagCounter.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:529)
    at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:421)
    at org.apache.flink.client.program.OptimizerPlanEnvironment.getOptimizedPlan(OptimizerPlanEnvironment.java:83)
    ... 7 more
Caused by: java.lang.ClassNotFoundException: org.apache.flink.streaming.connectors.twitter.TwitterSource$EndpointInitializer
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 15 more

但是,在程序中,我在下面的build.sbt中设置了TwitterSource库:

val flinkDependencies = Seq(
  "org.apache.flink" %% "flink-scala" % flinkVersion % "provided",
  "org.apache.flink" %% "flink-streaming-scala" % flinkVersion % "provided",
  "org.apache.flink" %% "flink-connector-twitter" % flinkVersion,
  "commons-logging" % "commons-logging" % "1.2",
  "org.apache.logging.log4j" % "log4j-core" % "2.11.2",
  "org.apache.commons" % "commons-text" % "1.6")

该应用程序在 IntelliJ 和 sbt buld/包中运行也没有问题,不会产生任何问题。如何解决此问题?

您需要

使用sbt assembly插件或任何其他允许创建Fat Jar(Uber Jar(的插件。目前您的软件包不包含外部库,flink 连接器被视为外部库,因为它们不包含在标准二进制构建中。因此,您实际上正在创建的软件包不包含twitter-connector,但 Flink 本身也不包含,这就是您获得ClassNotFoundException的原因。

我有一个胖(超级(罐子。当我分解它时,我可以看到连接器依赖项为wel。然而,当我将 jar 作为 flink 作业提交时,我得到了一个 classnotfoundexception。

可能是什么原因?

相关内容

  • 没有找到相关文章