zoukankan      html  css  js  c++  java
  • Flink 1.12.1 NoClassDefFoundError SourceFunction

    Flink 1.12.1 java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/functions/source/SourceFunction

    错误信息描述

    使用Idea运行项目,抛出以下异常

    java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/functions/source/SourceFunction
    	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.functions.source.SourceFunction
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    	... 7 more
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" 
    

    解决方案一

    修改pom文件,把里面与flink有关的scope为provided的代码行注释,类似以下效果

    <!-- This dependency is provided, because it should not be packaged into the JAR file. -->
    <dependency>
    	<groupId>org.apache.flink</groupId>
    	<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
    	<version>${flink.version}</version>
    	<!-- <scope>provided</scope> -->
    </dependency>
    <dependency>
    	<groupId>org.apache.flink</groupId>
    	<artifactId>flink-clients_${scala.binary.version}</artifactId>
    	<version>${flink.version}</version>
    	<!-- <scope>provided</scope> -->
    </dependency>
    

    刷新Maven依赖,重新运行项目

    maven reimport
    

    解决方案二

    我使用的是Idea 2020.3,通过调整idea配置,支持在项目运行时,将Provided的依赖有效

    进入Edit Configurations

    选择Modify options,选择Use classpath of module

    选择Inclue dependencies with "Provided" scope

  • 相关阅读:
    nginx+keepalived实现负载均衡nginx的高可用
    php7 安装swoole4.0.4
    Cannot find config.m4. Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module的 解决方法
    简析小黑是如何盗取cookie登录用户账号
    一个'&'引起md5签名不一致问题
    linux学习:curl与netcat用法整理
    swoole+websocket+redis实现一对一聊天
    使用COOKIE实现登录 VS 使用SESSION实现登录
    巧用PHP中__get()魔术方法
    用户表分表原理
  • 原文地址:https://www.cnblogs.com/fengzhentian/p/14853695.html
Copyright © 2011-2022 走看看