遇到报 java.lang.NoSuchMethodError 这个错误,基本可以确定是环境问题导致的
java.lang.NoSuchMethodError: org.apache.hadoop.fs.FileSystem.openFile
例如提示缺少这个 说明 运行过程搜索不到 org.apache.hadoop.fs.FileSystem 这个类
2.1 可以先尝试搜索引擎搜索下 FileSystem.openFile()/FileContext.openFile()
This is a method provided by both FileSystem and FileContext for advanced file opening options and, where implemented, an asynchrounous/lazy opening of a file.
Creates a builder to open a file, supporting options both standard and filesystem specific. The return value of the build() call is a Future<FSDataInputStream>, which must be waited on. The file opening may be asynchronous, and it may actually be postponed (including permission/existence checks) until reads are actually performed.
This API call was added to FileSystem and FileContext in Hadoop 3.3.0;
根据提示信息 这个是hadoop3.3 以后得版本引入的 说明运行过程没有加载到对应的jar包
2.2 借助gtp帮助我们快速定位对应的jar包 ,运行期间没有加载hadoop相关的jar包 hadoop-common-3.3.0.jar 或者 hadoop-hdfs-client-3.3.0.jar
2.3 去spark的jars目录中查看是否有对应的模块包 ls $SPARK_HOME/jars | grep hadoop-
查看是否有对应包或者模块, 如果没有我们则拷贝对应的包到这个目录中
2.4 如果有, 那么说明肯呢个是包冲突 因为haodop中也有对应的jar包 运行过程可能优先加载 hadoop的中jar包 . 正常情况优先加载$SPARK_HOME/jars
中的依赖包 注意: 我们也可能是因为pyspark版本高导致的降低即可
// 这两个参数科技帮助我们 展示启动那个过程加载了哪些jar包, 通过这个确定对应的jar包是否有正常加载
pyspark --conf "spark.driver.extraJavaOptions=-verbose:class" \
--conf "spark.executor.extraJavaOptions=-verbose:class" > driver_excutor.log 2>&1
# 1. 缺省某个包是否有指定的类
jar -tf xxx.jar | grep classname
# 示例
jar -tf hadoop-common-3.2.0.jar | grep FileSystem
# 2. 确定某个类中是否有对一个的方法 利用javap反向编码
# javap -cp xxx.jar complete_classname 可以展示某个类中有什么方法
javap -cp hadoop-common-3.2.0.jar org.apache.hadoop.fs.FileSystem | grep openFile
0