[英]Hadoop 2.6.0 Browsing filesystem Java
I have installed a basic hadoop cluster on CentOS 6.6 and want to write a few basic programs (browse the filesystem, delete/add files, etc) but I'm struggling to get even the most basic app working.我已经在 CentOS 6.6 上安装了一个基本的 hadoop 集群,并想编写一些基本的程序(浏览文件系统、删除/添加文件等),但我什至都在努力让最基本的应用程序工作。
When running some basic code to list the contents of a directory to the console I get the following error:当运行一些基本代码以将目录的内容列出到控制台时,我收到以下错误:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.ipc.RPC.getProxy(Ljava/lang/Class;JLjava/net/InetSocketAddress;Lorg/apache/hadoop/security/UserGroupInformation;Lorg/apache/hadoop/conf/Configuration;Ljavax/net/SocketFactory;ILorg/apache/hadoop/io/retry/RetryPolicy;Z)Lorg/apache/hadoop/ipc/VersionedProtocol;
at org.apache.hadoop.hdfs.DFSClient.createRPCNamenode(DFSClient.java:135)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:280)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:245)
at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:100)
at mapreducetest.MapreduceTest.App.main(App.java:36)
My pom.xml dependencies我的 pom.xml 依赖项
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
The code:编码:
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DistributedFileSystem;
public class App
{
public static void main( String[] args ) throws IOException, URISyntaxException
{
Configuration conf = new Configuration();
FileSystem fs = new DistributedFileSystem();
fs.initialize(new URI("hdfs://localhost:9000/"), conf);
for (FileStatus f :fs.listStatus(new Path("/")))
{
System.out.println(f.getPath().getName());
}
fs.close();
}
}
The error is being thrown after calling fs.initialize().调用 fs.initialize() 后抛出错误。 I'm really not sure what the issue is here.
我真的不确定这里的问题是什么。 Am I missing dependencies?
我是否缺少依赖项? Are they the wrong version?
他们是错误的版本吗?
I was running this by calling "java -jar app.jar .... etc" I should have been using "hadoop jar app.jar".我通过调用“java -jar app.jar .... etc”来运行它,我应该使用“hadoop jar app.jar”。
Worked as intended when I ran it correctly.当我正确运行它时按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.