Apache Flink WordCount示例 - 线程“main”中的异常java.lang.NoClassDefFoundError:org / apache / flink / api / common / functions / FlatMapFunction

时间:2016-10-16 17:47:35

标签: java maven intellij-idea apache-flink word-count

我跟着this guide,但如果我从IDE运行WordCount,我会收到异常

/usr/lib/jvm/java-8-oracle/bin/java -Didea.launcher.port=7536 -Didea.launcher.bin.path=/home/marc/Programs/idea-IC-162.2032.8/bin -Dfile.encoding=UTF-8 -classpath "/usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/nashorn.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-8-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfxswt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/management-agent.jar:/usr/lib/jvm/java-8-oracle/jre/lib/plugin.jar:/usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar:/home/marc/apache flink/flink.gelly/target/classes:/home/marc/Programs/idea-IC-162.2032.8/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain haw.bachelor.flink.gelly.WordCount
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/api/common/functions/FlatMapFunction
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.api.common.functions.FlatMapFunction
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more

我的环境:

  • Ubuntu 14.04 LTS
  • Oracle Java 8
  • Maven 3.0.5
  • intellij社区版

4 个答案:

答案 0 :(得分:7)

这是我更改的设置,错误消失了 here is what i changed

答案 1 :(得分:2)

在 Intellij IDEA (2020.3) 中,UI 略有不同。

步骤:

  1. 激活运行配置下拉菜单 Activate run-configuration dropdown
  2. 点击 Edit Configurations... Edit Run Configuration
  3. 点击 Modify Options Select Modify Options
  4. 选择include dependencies with "Provided" scope Select include dependencies with provided scope
  5. 点击“完成”

现在应该包含 Flink 源,这应该可以解决遇到的错误 - 它对我有用!

答案 2 :(得分:0)

如果在IDE中运行它,则必须选择" mainRunner"而不是" root"来自"运行配置"菜单。它使类路径加载了"提供的类"在项目中。

答案 3 :(得分:0)

我通过停用' build-jar'解决了这个问题。在IDE中的Maven中的配置文件。似乎将其关闭将使运行时类可用。