gpt4 book ai didi

java.lang.ClassNotFoundException : Class org. apache.hadoop.hdfs.DistributedFileSystem

转载 作者:行者123 更新时间:2023-12-02 11:22:56 46 4
gpt4 key购买 nike

我想使用hadoop-3.0运行以下程序:

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;


public class HDFSFileTest {
public static void main(String[]args) {
try {
String fileName="input/test.txt";
Configuration conf =new Configuration();
conf.set("fs.defaultFS","hdfs://localhost:9000");
conf.set("fs.hdfs.impl","org.apache.hadoop.hdfs.DistributedFileSystem");
FileSystem fs=FileSystem.get(conf);
if(fs.exists(new Path(fileName))) {
System.out.println("File exists!");
}
else {
System.out.println("File not exists!");
}
}
catch(Exception e){
e.printStackTrace();
}
}
}

但是当我在 eclipse 中执行代码时出现异常:

log4j:WARN No appenders could be found for logger 
(org.apache.hadoop.util.Shell).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
more info.
java.lang.RuntimeException: java.lang.ClassNotFoundException: Class
org.apache.hadoop.hdfs.DistributedFileSystem not found
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2559)
at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:3254)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:3286)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:123)
at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:3337)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:3305)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:476)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:225)
at HDFSFileTest.main(HDFSFileTest.java:13)
Caused by: java.lang.ClassNotFoundException: Class
org.apache.hadoop.hdfs.DistributedFileSystem not found
at

我检查了hadoop-common-3.0.1.jar、hadoop-hdfs-3.0.1.jar包,没有这样的类

 org.apache.hadoop.hdfs.DistributedFileSystem

最佳答案

也许你们只需要添加一些其他 jar 。

我之前也遇到过同样的问题,然后我碰巧添加了一些其他 jar ,如下所示。幸运的是,我成功了。

enter image description here

关于java.lang.ClassNotFoundException : Class org. apache.hadoop.hdfs.DistributedFileSystem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49799224/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com