记录:471
场景:使用IntelliJ IDEA本地启动调试Flink流计算时,报错一:加载DataStream报错java.lang.ClassNotFoundException。报错二:No ExecutorFactory found to execute the application。
版本:JDK 1.8,flink-1.11.6,IntelliJ IDEA 2021.2.3。
一、解决加载DataStream报错java.lang.ClassNotFoundException
1.前提
在代码工程中已经正确引入flink-streaming-java_2.11-1.11.6.jar,在此jar包存在org.apache.flink.streaming.api.datastream.DataStream类。
2.场景
在执行启动类的main函数时报错。
3.异常信息
java
java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/datastream/DataStream
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.streaming.api.datastream.DataStream
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
4.解决:
(1)选择菜单: Run => Edit Configurations...
(2)在 Run/Debug Configurations页面中,点击: Modify options
(3)在菜单列表中勾选: Add dependencies with "Provided" scope to classpath
(4)点击OK确认保存
菜单列表如图一:
二、解决No ExecutorFactory found to execute the application异常
1.异常信息
java
Exception in thread "main" java.lang.IllegalStateException: No ExecutorFactory found to execute the application.
at org.apache.flink.core.execution.DefaultExecutorServiceLoader.getExecutorFactory(DefaultExecutorServiceLoader.java:88)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.executeAsync(StreamExecutionEnvironment.java:1764)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.java:1665)
at org.apache.flink.streaming.api.environment.LocalStreamEnvironment.execute(LocalStreamEnvironment.java:73)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.java:1651)
2.解决
在代码工程pom.xml中添加依赖。
XML
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.11</artifactId>
<version>1.11.6</version>
<scope>provided</scope>
</dependency>
以上,感谢。
2023年9月5日