No FileSystem for scheme: hdfs问题

时间:2022-04-17 14:49:43

通过FileSystem.get(conf)初始化的时候,要通过静态加载来实现,其加载类的方法代码如下:

private static FileSystem createFileSystem(URI uri, Configuration conf
) throws IOException {
Class<?> clazz = conf.getClass("fs." + uri.getScheme() + ".impl", null);
if (clazz == null) {
throw new IOException("No FileSystem for scheme: " + uri.getScheme());
}
FileSystem fs = (FileSystem)ReflectionUtils.newInstance(clazz, conf);
fs.initialize(uri, conf);
return fs;
}

onf.getClass需要读取hadoop-common-x.jar下面的core-default.xml,但是这个xml里面没有fs.hdfs.impl的配置信息,所以需要将这个类给配置上去。

将hadoop-commom-x.jar里面的core-default.xml文件取出并修改,添加如下代码:

<property>
<name>fs.hdfs.impl</name>
<value>org.apache.hadoop.hdfs.DistributedFileSystem</value>
<description>The FileSystem for hdfs: uris.</description>
</property>

或者应用代码使用时候,自行添加:

configuration.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");