赞
踩
使用hdfs操作文件的时候遇到以下两个异常:
1.java.io.IOException: No FileSystem for scheme: hdfs
2.org.apache.hadoop.fs.UnsupportedFileSystemException: No FileSystem for scheme “file”
类似No FileSystem for scheme: hdfs (file)原因是jar包或打包问题。
依赖的jar包是hadoop-commons 和 hadoop-hdfs
Different JARs (hadoop-commons
forLocalFileSystem
,hadoop-hdfs
forDistributedFileSystem
) each contain a different file calledorg.apache.hadoop.fs.FileSystem
in theirMETA-INFO/services
directory. This file lists the canonical classnames of the filesystem implementations they want to declare (This is called a Service Provider Interface implemented viajava.util.ServiceLoader
, seeorg.apache.hadoop.FileSystem
line 2622).
When we usemaven-assembly-plugin
, it merges all our JARs into one, and allMETA-INFO/services/org.apache.hadoop.fs.FileSystem
overwrite each-other. Only one of these files remains (the last one that was added). In this case, theFileSystem
list fromhadoop-commons
overwrites the list fromhadoop-hdfs
, soDistributedFileSystem
was no longer declared.
1.通过配置方式:
// 这个解决hdfs问题
hadoopConf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
// 这个解决本地file问题
hadoopConf.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
2.通过打包插件方式
org.apache.maven.plugins maven-shade-plugin 2.3 package shadeCopyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。