当前位置: 首页 > news >正文

flink程序本地运行报: A JNI error has occurred和java.lang.NoClassDefFoundError

1.问题描述

        在idea中运行flink job程序出现如下错误:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/api/common/io/FileInputFormat
    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:650)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.api.common.io.FileInputFormat
    at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
    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

2.问题分析

2.1代码问题分析

package test;import org.apache.flink.api.java.io.TextInputFormat;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;/*** @Description* @Author * @Date 2024/5/23* @Version 1.0*/
public class ReadTextDemo {public static void main(String[] args) throws Exception {StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();TextInputFormat textInputFormat = new TextInputFormat(null);DataStreamSource<String> source = env.readFile(textInputFormat, "D:\\datatest\\readtext.txt");source.print();env.execute("readText test");}
}

        代码编译没有问题,但是却报类无法加载的异常,而且报错信息出现A JNI error has occurred,因此,猜测大概率和JDK有关,网上查了下解决方案:解决Java编译时错误:A JNI error has occurred,please check your installation and try again_java_脚本之家

        但是通过验证,本地的JDK环境配置没有问题:

        因此排除JDK问题的猜想。

2.2 pom配置问题分析

        类无法正常加载还一种可能是pom依赖出现了问题,pom配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>xxx-flink</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><flink.version>1.15.0</flink.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.apache.flink</groupId><artifactId>flink-streaming-java</artifactId><version>${flink.version}</version><scope>provided</scope></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-clients</artifactId><version>${flink.version}</version><scope>provided</scope></dependency></dependency></dependencies><build><plugins><plugin><!--<groupId>org.apache.maven.plugins</groupId>--><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin><plugin><artifactId>maven-assembly-plugin </artifactId><configuration><descriptorRefs><!-- 此处填写打包后jar包后添加的标识 --><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs><archive><manifest><!-- 此处填写程序的主入口(main方法) --><mainClass>cn.xxx.Main</mainClass></manifest></archive></configuration><executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions></plugin></plugins></build></project>

        对pom内容进行分析,发现flink jar依赖多了一行:

        <scope>provided</scope>表示为当前依赖在打包过程中,不需要打进去,需要由运行的环境来提供,因此怀疑是它导致的,然后就将它注解掉,再次运行,发现程序正常执行。

http://www.lryc.cn/news/355553.html

相关文章:

  • yolox-何为EMA?
  • Java:String、StringBuffer和StringBuilder的区别
  • 虚拟化技术 分布式资源调度
  • 【Element-plus】vue组合式中使用el-upload通过oss接口上传图片流程(可直接复制使用)
  • C++ 数据结构算法 学习笔记(33) -查找算法及企业级应用
  • 【Linux】在Ubuntu 16.04上安装Gerrit + PostgreSQL + Apache服务
  • 数据倾斜那些事儿
  • python考试成绩管理与分析:从列表到方差
  • Excel某列中有不连续的数据,怎么提取数据到新的列?
  • 翻译《The Old New Thing》- What does it mean when a display change is temporary?
  • 【C语言】char,short char,long char分别是多少字节,多少位,多少bit
  • 新V 系首批订单交付!苏州金龙助新疆游骏文旅集团打造旅运新标杆
  • 【Django】从零开始学Django【2】
  • 【leetcode--383赎金信(使用Counter一行代码结束战斗)】
  • pdf打开方式怎么设置默认?分享这几种设置方法
  • 杂谈|RestFul和http的区别
  • Nginx的Sub模块
  • 使用大模型做应用的一些问题
  • 2024 前端面试每日1小时
  • 2024.05.22学习记录
  • Redis与数据库同步指南:订阅Binlog实现数据一致性
  • Spring MVC+mybatis 项目入门:旅游网(二) dispatcher与controller与Spring MVC
  • 深入了解数据库与Java数据类型映射
  • 深刻解析 volatile 关键字和线程本地存储ThreadLocal
  • 羧甲基纤维素钠(CMC-Na)市场规模不断增长 我国生产企业众多
  • 网红郭有才是怎么火起来的
  • 小米8SE刷root(面具)
  • 如果创办Google
  • 邦芒职场:揭秘影响你职场收入的九大细节
  • Petalinux 制作ZYNQ镜像文件流程