• 使用IntelliJ IDEA本地启动调试Flink流计算工程的2个异常解决


    记录: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.异常信息

    1. java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/datastream/DataStream
    2. at java.lang.Class.getDeclaredMethods0(Native Method)
    3. at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    4. at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    5. at java.lang.Class.getMethod0(Class.java:3018)
    6. at java.lang.Class.getMethod(Class.java:1784)
    7. at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    8. at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
    9. Caused by: java.lang.ClassNotFoundException: org.apache.flink.streaming.api.datastream.DataStream
    10. at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    11. at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    12. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    13. at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    14. ... 7 more
    15. 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.异常信息

    1. Exception in thread "main" java.lang.IllegalStateException: No ExecutorFactory found to execute the application.
    2. at org.apache.flink.core.execution.DefaultExecutorServiceLoader.getExecutorFactory(DefaultExecutorServiceLoader.java:88)
    3. at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.executeAsync(StreamExecutionEnvironment.java:1764)
    4. at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.java:1665)
    5. at org.apache.flink.streaming.api.environment.LocalStreamEnvironment.execute(LocalStreamEnvironment.java:73)
    6. at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.java:1651)

    2.解决

    在代码工程pom.xml中添加依赖。

    1. <dependency>
    2. <groupId>org.apache.flinkgroupId>
    3. <artifactId>flink-clients_2.11artifactId>
    4. <version>1.11.6version>
    5. <scope>providedscope>
    6. dependency>

    以上,感谢。

    2023年9月5日

  • 相关阅读:
    计算机网络(Learning Records)
    YAML配置文件
    【多线程】定时器 Timer
    使用 Aeraki Mesh 实现零代码侵入的 Dubbo 服务调用跟踪
    go中的map
    mysql数据类型的一些坑
    MyBatis动态SQL(if、choose、when和otherwise)标签
    JAVA--word等文件转PDF工具类
    网络编程day5作业
    JMeter动态线程组和动态吞吐量
  • 原文地址:https://blog.csdn.net/zhangbeizhen18/article/details/132700220