我正在尝试设置对 HDFS 的调用以使用 FileSystem 从中获取文件:
FileSystem fs = new FileSystem.get(new URI.create(uri), conf);
但是我得到了这两个错误,即使我调用了所有的库
Error:(46, 39) java: cannot find symbol
symbol: class get
location: class org.apache.hadoop.fs.FileSystem
Error:(46, 47) java: cannot find symbol
symbol: method create(java.lang.String)
location: class org.apache.commons.httpclient.URI
这适用于 hadoop 2.7.7 版本。我已经尝试导入孔库 org.apache.hadoop.fs.*; ,但仍然是该方法get并且create当我尝试在以下行中使用它们时不存在: FileSystem fs = new FileSystem.get(URI.create(usi), conf)
import org.apache.commons.httpclient.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
public class Test {
public static void main(String []args) {
String uri = "hdfs://localhost:9000/data.json";
Configuration conf = new Configuration();
//cannot find symbol get
//Cannot find symbol create
FileSystem fs = new FileSystem.get(new URI.create(uri), conf);
InputStream in = null;
try {
in = fs.open(new Path(uri));
IOUtils.copyBytes(in, System.out, 4096, false);
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeStream(in);
}
}
}
这是我的 POM.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.boeing.bedl</groupId>
<artifactId>IngestionData</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-common</artifactId>
<version>2.7.7</version>
</dependency>
猛跑小猪
当年话下
相关分类