irpas技术客

No FileSystem for scheme:hdfs and Class org.apache.hadoop.DistributedFileSystem

大大的周 3228

在获取 Hadoop 文件系统对象时,如下所示

FileSystem fs = FileSystem.get(hdfsUrl,configuration);

错误一

如果收到以下错误:

"No FileSystem for scheme:hdfs"

可以通过在配置中设置以下 2 个属性来解决它

configuration.set("fs.hdfs.impl","org.apache.hadoop.hdfs.DistributedFileSystem"); configuration.set("fs.file.impl", "org.apache.hadoop.fs.LocalFileSystem"); 错误二

现在,您可能会收到如下新错误:

java.lang.ClassNotFoundException: Class org.apache.hadoop.hdfs.DistributedFileSystem not found 解决方案一

Hadoop-common.jar 使用 Thread.currentThread.getContextClassLoader() 和 configuration.getClassLoader 来加载类。因此,如果您使用

Thread.currentThread.setContextClassLoader(yourClassLoader); configuration.setClassLoader(yourClassLoader);

就能够从其他 hadoop jar 加载所需的类(例如 hadoop-hdfs)

解决方案二

校验下,是否是jar包的问题:

双击 shift,输入??DistributedFileSystem。如下图,则说明包没问题

如果下拉框中是? 空白?

?

说明需要加对应的jar包了:

<dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-hdfs</artifactId> <version>2.6.0</version> </dependency>

?如果还报错,说明 集群使用的默认库里的相关的依赖包 与 hadoop-hdfs中依赖的包? 存在有冲突!需要把包的版本保持一致(确保远程不会有maven依赖的conflicts)。注意这个坑!

比如我司默认的是 2.6.0-cdhmdzz5.12.1版本

如果您需要更多帮助,请告诉我。如果你觉得这有点用,别忘了点赞。

部分参考

java - No FileSystem for scheme:hdfs and Class org.apache.hadoop.DistributedFileSystem not found - Stack Overflow


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #no #filesystem #for #schemehdfs #and #class #在获取